Personally, I still like keeping things organized but I don't want to sacrifice performance for it. So, I've started using the following approach for all my sites:
- Create two ColdFusion pages (or PHP, Ruby, etc) that change the mime type to "text/js" and "text/css" respectively.
- Then include all the appropriate js or css files using <cfinclude>.
/* js_compilation.cfm*/
<cfcontent type="text/js">
<cfinclude template="js/core.js">
<cfinclude template="js/prototype.js">
<cfinclude templat="js/rico.js">
- Lastly, you should simply reference that file in the Head section of the calling page.
<script src="js_compilation.cfm" type="text/js">
Do the same thing for all your assorted CSS files and you're load time should be significantly improved without sacrificing organization. You can keep your file structure simple and efficient.
Cheers,
Todd
PS-I know everyone should be crunching their JS files into one library but we can't all afford to do that. This is a simple step that everyone can handle.
4 comments:
hi todd,
i'd like to use your solution to organize our .js-files but it has the drawback that the javascript isn't cached anymore (HTTP/1.1 304 Not Modified) did you find a solution for this problem?
nevermind, found a nice solution, working on the network layer:
c60;cfheader name="expires" value="now()+43200"c62;
c60;cfheader name="Cache-Control" value="max-age=43200"c62;
gets the js cached for ´10h (one workday) later on we gonna modify our build-process using a version number coded into the url, and set expires to "a couple if years", like its explained here:
http://www.die.net/musings/page_load_time/
cheers jasper
Good call with the expire header. That's definitely the way to handle it.
All the best with your Ajax work.
-Todd
I know this is old, but I just thought I'd let you know that it came in handy four years later. :)
Post a Comment