I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 7824
39879 credits Members referred : 3
« Reply #1 on: Oct 15, 2007, 09:54:15 PM »
This will produce overhead as well too. Also you should play with the headers more, so that the file wont be loaded on every pageview but it will be cached by the browser.
In my opinion you should use the output of that script in a text file.
Tim Nash
Global Moderator Community Supporter?
Internet Junkie
Posts: 2169
5008 credits Members referred : 2
Venture Skills - New Media & IT group
« Reply #2 on: Oct 15, 2007, 10:03:01 PM »
yes I think the overheads only balance for larger files, still if you have a complex css layout it does speed things up a bit I will come back with some stats in a few minutes, While I agree caching the file would be a more useful method it does sort of beat the point of doing it on the fly, you might as well strip out the whitespace during or proceeding the upload and not on the server.
Tim Nash
Global Moderator Community Supporter?
Internet Junkie
Posts: 2169
5008 credits Members referred : 2
Venture Skills - New Media & IT group
« Reply #5 on: Oct 16, 2007, 12:09:15 PM »
I guess using the term compress has caused some confusion, the code above simply strips whitespaces which as olaf says improves load time rather then dramatically reducing bandwidth its a speed up process. Obviously if your css has only 5 lines of code then this is no use to you, conversely if you have a file with 20k lines of css code (apart from a serious code issue) this won't help either.
On a wordpress theme I tried it on it provided a couple of mini second improvements on the load time under test conditions I plan on using it on my own blog theme to test it in the real world, such a small difference might not be amazing but hey. One of the things I am thinking of doing is stripping out comments as well but I think that this will actually cause a delay in load time as its a lot more intensive.
Nikolas' Servant's Servant
Posts: 29
178 credits Members referred : 0
« Reply #7 on: Oct 16, 2007, 12:24:34 PM »
If you're after speeding up page loading, you don't want to force the browser to refetch the same CSS every time (especially if you use the same CSS on multiple pages), so the If-Modified-Since handling code is important if you're going to process the files in PHP (it's better than server-side caching).
Depending on the network throughput, the smaller sizes obtained with gzip compression may improve page load time, or may not --- it depends on where the bottleneck is.
Community Supporter?
OMG!I am geek
Gender:
Posts: 56
364 credits Members referred : 0
Schwa?
« Reply #8 on: Jan 03, 2008, 04:01:33 AM »
I can detail what I do if there is more interest (with code that is)
1) have a global CSS identifier - like a number - which refers to the current code release 2) add each css file to a php array 3) have php stip out the whitespaces of each element, comments, etc... and load them all into one stream 4) send a not modified header - expires 1 year 5) gzip content and send as one request via <link ... tag
This is kind of a hybrid. i don't write a static cache file - but I do send a heavy cache header. I also reduce the amount of http requests - so I can have the separate css files for better css/oop - hah.
Finally, when I do push out a change, I change that number so that those pages have a different 'link' and the expires header no longer applies.
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 7824
39879 credits Members referred : 3
« Reply #9 on: Jan 05, 2008, 01:19:07 PM »
Aaron your solution looks good, but the 1 year expiriation and the gzip thing can cause problems.
Before a few days I had nothing to do in army - but I could use a pc - so I created a css compressor. The script takes a css file, removes comments \n, white spaces and then saves the file. In the next level I will make the script detect all the css files in the web server (all files in a specific directory) and compress them. After that I will release it as an open source project.
BTW the results are great even in small files. I used the script in a couple of standard css files (around 5kb with no comments) and the result was up to 50% compression.
Community Supporter?
OMG!I am geek
Gender:
Posts: 56
364 credits Members referred : 0
Schwa?
« Reply #10 on: Jan 06, 2008, 06:25:29 PM »
What specific problems are you referring to?
The gzip responds to how the browser sends its accept header - so no gzip if it doesn't say it can't accept. The expiration/caching will either cache for a year or ... not? The only thing I could think you're referring to is maybe someone getting a corrupt cache?
Cool - it'll be cool to see what you come up with. I use my method on my work site (Fortune company - I just can't say what site... you know how it goes) - and haven't found any issues yet - doesn't mean that it doesn'tw ork - maybe people just didn't complain? hahaha
The biggest change that was made was to combine them all into one file - so single http request. The server admins were very much happy about that
I am a metal monkey!
Administrator Community Supporter?
Jedai Sword Master
Gender:
Posts: 7824
39879 credits Members referred : 3
« Reply #11 on: Jan 07, 2008, 06:05:04 PM »
I was talking for :
1) Server overhead. The gzip compression is great to save bandwidth and make the page download faster, but it is not good for busy sites, especially when your server has small capacity.
2) The cache header may be a problem when you are making changes to your site frequently. Of course this is a problem that can be solved easily (for instance you can add a get variable to indicate the version, css.php?v=1...)
Community Supporter?
OMG!I am geek
Gender:
Posts: 56
364 credits Members referred : 0
Schwa?
« Reply #12 on: Jan 08, 2008, 05:10:49 AM »
Ok - cool. I was curious what you were referring to.
As for the server load - I guess it might be worthwhile to generate cache of them - you would be able to determine from the header what to send, the plain css or the obz'd file. Eh - now we're just talking about almost too much premature optimization. I tend to overthink things from time to time. heh.
Yep - with the headers - you def have to send a different identifier with the url for the css file. I sent mine as a 'directory' instead of a get - cuz I'm afraid that some browsers might start ignoring that - cuz why would a css file need get variables, you know? heh.
Anyway, thanks for explaining.
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7246