NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page PHP - Dynamic Loader (for CSS, JS files)

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 07-28-2008, 10:44 PM THREAD STARTER               #1 (permalink)
i love automation
 
xrvel's Avatar
Join Date: Nov 2007
Location: xrvel.com
Posts: 1,620
xrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant future
 




Smile PHP - Dynamic Loader (for CSS, JS files)


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 Code:
<link rel="stylesheet" type="text/css" href="dynamic-loader.css?load=css1;css2" />
To add compression, use
HTML Code:
<link rel="stylesheet" type="text/css" href="dynamic-loader.css?load=css1;css2&amp;compress=1" />
Example #2, you want to load "js1.js" and "js2.js"
????: NamePros.com http://www.namepros.com/code/497829-php-dynamic-loader-css-javascript-files.html
HTML Code:
<script type="text/javascript" href="dynamic-loader.js?load=js1;js2&amp;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
__________________
xrvel is offline  
Old 07-29-2008, 09:26 AM   #2 (permalink)
NamePros Member
Join Date: Jul 2008
Posts: 147
rjmlar is an unknown quantity at this point
 



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!
rjmlar is offline  
Old 07-29-2008, 09:37 AM THREAD STARTER               #3 (permalink)
i love automation
 
xrvel's Avatar
Join Date: Nov 2007
Location: xrvel.com
Posts: 1,620
xrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant futurexrvel has a brilliant future
 




Thank you
I hope this script can solve the redundant HTTP requests
????: NamePros.com http://www.namepros.com/showthread.php?t=497829

Originally Posted by rjmlar
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!
__________________
xrvel is offline  
Old 08-25-2008, 08:42 AM   #4 (permalink)
Senior Member
 
bbalegere's Avatar
Join Date: Jul 2005
Location: Bangalore
Posts: 1,271
bbalegere is just really nicebbalegere is just really nicebbalegere is just really nicebbalegere is just really nicebbalegere is just really nice
 



Does this script decrease page load time?
bbalegere is offline  
Old 08-25-2008, 06:19 PM   #5 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
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/
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Last edited by Peter; 08-25-2008 at 06:27 PM.
Peter is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:21 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger