ASP.NET MVC 5 - Stylebundle Cdnfallbackexpression Questions

asp.net mvc 5 - StyleBundle CdnFallbackExpression questions?

1) This is a bug in the Microsoft ASP.NET Optimization Framework, documented here.

2) The solution is to modify the CdnFallbackExpression to be a javascript function that both checks for the stylesheet and loads the fallback, thus ignoring the bad script from the Optimization Framework.

Here is solution which provides a StyleBundle extension method to solve the problem: Style Bundle Fallback.

3) There should be unminified version like bootstrap.css (not bootstrap.min.css). When you build your web application for release it uses .min version. More here: Bundler not including .min files.

4) No, you can't use multiple CSS files with CDN (each of them must have its own bundle). Here is an article that explains when to use a CDN (or not) and why: Know When To CDN.

MVC CDN fallback for Style Bundle

TLDR;

Check out my solution which provides a StyleBundle extension method to solve the problem.

Style Bundle Fallback

Also

Yes there is a bug in the Microsoft ASP.NET Optimization Framework, documented here.

The solution is to modify the CdnFallbackExpression to be a javascript function that both checks for the stylesheet and loads the fallback, thus ignoring the bad script from the Optimization Framework.

There are a couple of tricky parts, especially checking for a stylesheet being loaded when it comes from another domain, like most CDN sources.

I have a solution on GitHub that you can use until the issue is fixed in the framework; however, I'd still watch out for the tricky part of determining when the stylesheet is actually loaded.

Accessing CDN bundles on different ASP.Net MVC site

I ended-up using the following solution for the CDN website.

https://stackoverflow.com/a/26402383/2663033

The main website then used the appropriate MVC route of the CDN website for the style "href" and the script "src", which redirected to the appropriately versioned content or script bundle.

Bundle JS files using CDN and integrity attribute

Partial answer.

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

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

You also can include integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" part in RenderFormat, but it does not look like a good solution.



Related Topics



Leave a reply



Submit