[Javascript] external script cache and script stripping

Mike Dougherty mdougherty at pbp.com
Fri Oct 8 12:55:55 CDT 2004


I did some analysis on one of the modules in my client-side js-driven application.

To my understanding, the customer's browser will cache the external script files.  To improve the 
perceived performance of the application (which currently feels slow to start because of initial 
download time) - i was considering delivering several of these scripts on each of the preceeding 
pages on the site so the user can have already cached the external scripts before they reach the 
application page. Imagine the user clicks through 4 pages before using this interactive js app - 
deliver scripts 1-5 on page 1, 6-10 on page 2, 11-15 on page 3 even though they are not used on 
those pages.  When page 4 uses all 20 scripts, the download time is only for scripts 16-20.  Call 
it a script preload strategy.  At this point, don't worry about the actual implementation - just 
the concept of it.

Also- by removing tabs (chr(9)), extra spaces around operators (" = "," + "), and block comments 
(/* */) the file is now 45% smaller (29744b -> 19551b)  The unstripped code in 20 files is 109Kb. 
 I plan to have a custom control running server-side to automatically compare the source version 
against the stripped version and "recomile" if the source is newer - because manually maintaining 
versions would be painful for the lazy developer (myself) [note: i use the term 'stripped' because 
i have no intention of trying to "compress" the file by tokenizing keywords/variables, etc. as i 
have seen available.]

What are your opinions of 1. my idea of script preload, and 2. having a developer "source" version 
of external javascripts and a "stripped" version for delivery to browsers?



More information about the Javascript mailing list