Batch JS files using CDN attribute and integrity

In ASP.NET MVC 5, is it possible to use BundleColletion.UseCdn and render it with an HTML integrity attribute? For example, is there a way to do this:

 bundles.UseCdn = true; bundles.Add( new ScriptBundle("~/bundles/jquery", "https://code.jquery.com/jquery-3.1.1.min.js") .Include("~/Scripts/js/jquery/jquery-3.1.1.min.js") ); 

do like that?

 <script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script> 
+6
source share
1 answer

Partial answer.

To add the crossorigin = "anonymous" attribute, you can use @ Scripts.RenderFormat

 @Scripts.RenderFormat("<script type=\"text/javascript\" src=\"{0}\" crossorigin=\"anonymous\"></script>", "~/bundles/jquery") 

You can also enable the integrity function = "sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8 =" in RenderFormat, but that doesn't seem like a good solution.

+2
source

Source: https://habr.com/ru/post/1015077/


All Articles