2

While maintaining the sites our development team has created, we have come across include files and plugins that have proven to be very useful to more then one part of our applications. Most of these modules have come with two different files, a normal source file and a min file. Seeing that the performance and speed of a page can be increased by minimizing the size of the file, we're looking into doing that to our pages as well.

The problem that we run into is a lot of our normal pages (written in ASP classic) is a mix of HTML, ASP, Javascript, CSS, and include files. We have some pages that have their JS both in include files and in the page, depending on if the function is only really used in that page or if it's used in many other pages. For example, we have a common.js and an ajax.js file, both are used in a lot of pages, but not all of them. As well as having some functions in a page that doesn't really make sense to put into one master page.

What I have seen a few other people do online is use one master JS file and place all of their javascript into that, minify it, gzip it, and only use that on their production server. Again, this would be great, but I don't know if that fully works for our purposes.

What I'm looking for is some direction to go with on this. I'm in favor of taking all of our JS and putting it in one include file, and just having it included in every page that is hit. However, not every page we have needs every bit of JS. So would it be worth the compilation and minifying of the files into one master file and include it everywhere, or would it be better to minify all other files and still include them on a need-to-use basis?

2
  • What's your priority here? Reduce bandwidth, server performance, client performance, obfuscation or learning? Commented Mar 27, 2012 at 22:14
  • Learning, more then anything. We're mainly looking at how effective it would be for us and what other practices there are when it comes to minification. Ultimately, I think we're looking for obfuscation and client performance. Commented Mar 28, 2012 at 19:58

1 Answer 1

4

I suppose the 80-20 rule might apply here.

Suppose that all your pages have 80% of common JS code. Identify it, make it into a single file and include everywhere.

The rest is page-specific; if some of it can be reused across a meaningful subset of pages, put it to another file, or several such files. If you have some truly unique code on some pages, leave it as is.

You will end up with something like this:

  • common.js // included on each of 100 pages;
  • foo.js // used on 10 foo-related pages
  • bar.js // used on 7 bar-related pages

etc.

Your typical page will include common.js and maybe a specific file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.