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
Relative Padding Is Relative to What
Change Only One of Multiple Backgrounds on Hover
Background Color on Input Type=Button :Hover State Sticks in Ie
How to Prevent Hidden Element to Be Shown When Focused in Chrome
How to Set Up a Dynamic Grid Based on Flex or Grid
Stop Chrome from Auto Styling Input Type=Search
CSS Border Shorthand When Each Border Has a Different Width
How to Create a Style Element and Append to Head in React
CSS Transition Max-Height Back to 0 Not Working
CSS Selector for First Element of Visual (Block Reflow) Row
Change Color of Svg Background-Image (Bootstrap 4 Carousel)
Css: What This Asterisk (*) Does
Rails Images and Assets Not Being Loaded Properly
How Do Make My Website Resize Automatically When the Screen Resolution Changes
How to Find "Emulate CSS Media" in Google Chrome