Dynadot

PHP - Dynamic Loader (for CSS, JS files)

Spaceship Spaceship
Watch

xrvel

i love automationVIP Member
Impact
163
What does this script do ?
  1. Load multiple JS / CSS files at once. (Purpose : reducing number of HTTP requests).
  2. Compress JS / CSS files. By removing tabs, new lines, etc. (Purpose : reducing file size).
    For CSS files :
    • replacing "font-weight:bold" with "font-weight:700" (minus 1 character).
    • replacing "#FF5500" with "#F50" (minus 3 characters).
    • replacing more extra characters.

How to use ?

Example #1, you want to load "css1.css" and "css2.css"
HTML:
<link rel="stylesheet" type="text/css" href="dynamic-loader.css?load=css1;css2" />

To add compression, use
HTML:
<link rel="stylesheet" type="text/css" href="dynamic-loader.css?load=css1;css2&compress=1" />

Example #2, you want to load "js1.js" and "js2.js"
HTML:
<script type="text/javascript" href="dynamic-loader.js?load=js1;js2&compress=3"></script>

There are several level of compression (compress=1, compress=2, etc).
More information of compression level, please read "dynamic-loader.php".

If you want to compress JS file :
  1. You may not use single line comment (double slashes), use multi line comment instead (/* */).
  2. Put semicolon on the end of line.

Download :)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
I'm working on a site that uses 2 main style sheets combined. With some pages are added a 3rd and 4th style sheet. My css is heavily commented and I need to keep it that way for a while. Saving bytes here and there with shorthand and compression doesn't affect efficiency all that much, but redundant http requests matter a lot.

I'll give your script a try, thanks for posting!
 
0
•••
Thank you :)
I hope this script can solve the redundant HTTP requests :)

rjmlar said:
I'm working on a site that uses 2 main style sheets combined. With some pages are added a 3rd and 4th style sheet. My css is heavily commented and I need to keep it that way for a while. Saving bytes here and there with shorthand and compression doesn't affect efficiency all that much, but redundant http requests matter a lot.

I'll give your script a try, thanks for posting!
 
0
•••
Does this script decrease page load time?
 
0
•••
1 problem I forsee with such a system is the lack of ability to cache the style sheets etc.

If most of your visits are repeat visits then the chances are they have those files cached and providing they have not changed they will not be redownloaded.

Another cheat that can speed up page loads is to have for example your site running off of domain.com but javascript and css or images running off of assets.domain.com.

Browsers see domain.com and assets.domain.com as being different hosts. Browsers limit the amount of downloads for a specific host so doing this doubles the amount of http requests the browser will run at any 1 time on the site.

Other good methods for speeding up websites is to have for example javascript at the end of the page instead of in the header.

If using firefox a good extension that you can use to help find problems is yslow developed by Yahoo. This extension needs firebug to run but is handy. If interested in this type of thing a book that is fairly good (and writen by 1 of the people involved with yslow) is http://oreilly.com/catalog/9780596529307/
 
Last edited:
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back