htmlscriptbundle

How to use script bundles in plain html (not cshtml)?


Before asking this question, I read the following two questions in Stack Overflow to avoid duplicate questions:

1) @Render.Scripts in plain .html file - not in .cshtml

2) Rendering the script bundle in a plain HTML page

May I know how to use script bundles in plain html file (something like @Scripts.Render("~/bundles/angular") in cshtml)?

I want to bundle more than one script file (to compress and load them together) and use the bundle in plain html. This bundle is going to be used in more than one html file.

Please advise.


Solution

  • You should use a script minifier/bundler, like https://jscompress.com/. Choose the "Upload Javascript Files" tab, and upload all the scripts you want there. It will produce a single, minified and bundled file, just like ASP.NET would. You can then include that single file in your code just like you wrote.