Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compressing JS and CSS in Static HTML Files

The output from Sphinx, the python documentation generator, results in a large number of HTML files. Each one has a header with a large number of JavaScript and CSS includes:

<link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="stylesheet" type="text/css" href="../_static/custom.css" />
<link rel="stylesheet" type="text/css" href="../_static/colorbox/colorbox.css" />
<script type="text/javascript" src="../_static/colorbox/jquery.colorbox-min.js"></script>

Most of these are minified individually, but this is still suboptimal because it requires separate requests to the webserver when the client's cache is empty. Is there a tool like YUI Compressor or the Closure Compiler that will take HTML files as input, compress all of the individual externally-linked scripts, and then rewrite the output? This would be similar to what django_compressor does.

like image 281
jterrace Avatar asked Sep 06 '12 14:09

jterrace


1 Answers

Agree with Above answer.

You can do one other thing.

Put all Scripts after Body instead of header. May be it will increase your loading speed.

like image 187
Hemal Monani Avatar answered Sep 22 '22 17:09

Hemal Monani