Organizing Javascript and CSS Resources

I do a lot of work on a really large .NET webforms application, and organizing js and css files can be a challenge.

I picked up the technique to nest *.aspx.js files beneath their corresponding *.aspx file (the same way visual studio nests the code behind) from a previous project. I expanded on this a bit recently by also nesting *.aspx.css files, and then automatically adding a reference from the MasterPage if the files exist.

This allows me to build a "core" system for css and javascript that will be loaded globally on all pages. Then individual pages that require unique logic or style can load their own resources independently, without inadvertently interfering with other pages.

So far this technique has been working pretty well for me. Suggestions welcome.

Posted on May 30, 2012

More by Ben Harrison

View profile