In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how ASP.NET MVC 4 bundles and shrinks multiple css and js files, I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.
Multiple css and js files can be bundled in ASP.NET MVC 4 to reduce HTTP requests, and css and js files can be compressed (shrunk), which can increase the loading speed of the website. Let's take a look at the css file of the blog Park. Before ASP.NET MVC 4, we introduced the css method as follows:
Use F12 in IE to view the results, as shown in the figure:
In ASP.NET MVC 4, introduce the css file using the following writing:
Rerun, and the result is as follows:
You can clearly see that when css was introduced in ASP.NET MVC 4 using the new method, the site runtime not only merged the css files but also compressed the code in css. Double-click the css file, and you can see in the response body:
Js files are handled in the same way as css, and the following methods are introduced:
When bundled in ASP.NET MVC 4, the css collation is that reset.css and normalize.css are loaded first, and other files are sorted alphabetically. Similarly, js collation is sorted by jquery.js, and other jquery-ui.js files are sorted by acronym. Sometimes we need to load different css or js files on different pages to reduce unnecessary files, so let's see how to customize a bundle.
Add the following code to the Global.asax.cs file Application_Start ():
/ / define a bundle named "mycss", and js corresponds to new JsMinify ()
Var b = new Bundle ("~ / mycss", new CssMinify ())
/ / add all css files under the Content folder to the bundle
/ / the third parameter, false, indicates that subfolders under the Content folder are not added to the bundle.
B.AddDirectory ("~ / Content", "* .css", false)
/ / add to BundleTable
BundleTable.Bundles.Add (b)
In this way, you can add the following code to the page you need to use:
These are all the contents of the article "how ASP.NET MVC 4 binds and shrinks multiple css and js files". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.