use action methods for rendering CSS and JavaScripts (like http://site.com/js/somejs).
It would make it possible to read the JavaScript or CSS from many sources, pack them together and then cache (OutputCache attribute).
Check out ASP.NET Web Optimization in ASP.NET MVC 4. Read more on Howard’s blog here: http://codebetter.com/howarddierking/2012/08/03/whats-next-for-asp-net-web-optimization/
9 comments
-
Andrey Kuleshov commented
It worths to note Cassette from Andrew Davey here
https://github.com/andrewdavey/cassette -
Sergiy Galay commented
Telerik mvc controls already have such functionality (combine/pack/cache css/js files). It's very useful. It would be very nice to see that integrated into mvc framework
-
Emmanuel Morales
commented
This should be baked into the framework or provided as an extension and utilize a provider model to swap out the base implementation if desired.
-
Andrew Pierro
commented
There are tons of great things like this out there. I am also using SquishIt myself now. However, this really should be a part of MVC as it is something which almost everyone is going to need at some point. Also, simple combining or packing is easy, but I would prefer to have an 'official MVC' solution which I new was going to handle all the URL rewrites correctly and would better support things like pulling the CSS/JS from an embedded resource.
-
Gregory Waxman
commented
https://github.com/jetheredge/SquishIt handles this as well and lets you maintain caching configuration through your web.config.
-
Sergey Fadeev
commented
http://combres.codeplex.com/ - .NET library which enables minification, compression, combination, and caching of JavaScript and CSS resources for ASP.NET and ASP.NET MVC web applications.
-
mysterious commented
I've done this and it works like a charm.
-
Wayne Brantley
commented
chirpy http://chirpy.codeplex.com/ to minify/combine and t4mvc to generate these checksums for you all done at compile time. http://mvccontrib.codeplex.com/wikipage?title=T4MVC&referringTitle=Documentation
-
john commented
this is what i nearly do. slightly different. i have
http://site.com/js/[files_basic_checksum].js
where files_basic_checksum is the filename + lastmodifieddate + compressionlevel of the js files im including as one then md5ed.
that way if i change one file, or decide to minify the file more, the url changes and the user gets a new copy.
also since the url for that file will always be unique and if any changes to the files happen its a new URL, i can set the cache for that file for 10 years users only ever have to download it once.i also do this for CSS files.
for master pages, i have a global set of css and js files I include on every page.