, , ,

this blog post gave me new ways of speeding up page loads.


the learning is that js file requests are blocking. so either reduce the number of js or load them dynamically.

we tried to apply these into our work. combining js into one has some practical difficulties.
developers are used to working with their respective files. multiple checkout of the same file leads to other issues and so on. we did this sort of hack and it works fine.

0. we use tomcat and jsp in our web app. the explanation is relevant in this context.
1. configure tomcat to treat myjs (it could be anything) as a jsp extension ie., it would parse files
of myjs extension.
2. in the alljs.myjs file have as many . These are the js files that need to be combined.
3. the include directive in jsp does a textual copy of files. thus all the required jsps are combined into
one dynamically.
4. the jsp or html page where alljs.myjs is required is referred as
<script language="javascript" src="/some/place/alljs.myjs" />
Since the language is explicitly specified as javascript, the browser isnt very strict about .js extension.
5. In our case, we combined 5 javascript files into one dynamically. While retaining their individuality
at development time.
6. by using gzip and minifying the jses, the performance has improved much.

The drawback with this approach is that the myjs file is not cached by the browser the way .js files are. This could be circumvented by some setting cache-control, Expires etc on resources of *.myjs type in Apache. But we are yet to try this. would update this post after we find something.

Update :
1. Minifying the js can be done programatically by using this java code. The code is available in all the major languages here http://www.crockford.com/javascript/jsmin.html

About these ads