PDA

View Full Version : gzip your CSS


hidjra
03-16-2006, 10:00 PM
Step 1
Create a new file, call it 'gzip-css.php' copy the following snippet and upload to the 'vbulletin_css' folder:


<?php
ob_start('ob_gzhandler');
header('Content-type: text/css; charset: UTF-8');
header('Cache-Control: must-revalidate');
header('Expires: Thu, 3 Jan 2007 23:53:18 GMT');
?>


Step 2
create a .htaccess file, put this in the same directory as above, put in the following snippet:


php_value auto_prepend_file gzip-css.php


Step 3
Open the adminfunctions_template.php file located in the 'includes' directory. Look for the following:


$cssfilename = 'clientscript/vbulletin_css/style-' . substr(md5(microtime()), 8, 8) . '-' . str_pad($styleid, 5, '0', STR_PAD_LEFT) . '.php';


change it to


$cssfilename = 'clientscript/vbulletin_css/style-' . substr(md5(microtime()), 8, 8) . '-' . str_pad($styleid, 5, '0', STR_PAD_LEFT) . '.css';


Now login to you vb control panel, re-generate the css file and your done. Enjoy ;)

daklay
03-16-2006, 10:56 PM
FIRST POST

Awesomse idea man :banana:

Andreas
03-16-2006, 11:04 PM
IMHO it would be easeir to just use mod_gzip ?

yinyang
03-17-2006, 01:30 AM
what's this for?

aladinliverpool
03-17-2006, 02:34 AM
its for gzip'ing your CSS!

like gzip'ing up your coat when its chilly. ;)

Zia
03-17-2006, 04:44 AM
umm gzip css ?
confused... it should help to load the page faster ?

mod_gzip ..its possible to use it in shared server?

Zachery
03-17-2006, 03:50 PM
Hmm, I wouldn;'st suggest that, at least if I understand some things. I believe that IE has some issues cacheing gziped pages, and the CSS file should only be requested a few times before cached, thus why we have it as a file.

Snake
03-17-2006, 04:56 PM
Thanks!

Zia
03-17-2006, 05:05 PM
and the CSS file should only be requested a few times before cached, thus why we have it as a file.

that means this edit will make the css "save as files" ???!!

this option allready in vb's acp.

goyo
03-17-2006, 05:52 PM
that means this edit will make the css "save as files" ???!!

this option allready in vb's acp.

No... this means your server zipping up your .ccs file before sending to your browser. Thus less bandwidth usage... although I don't see the real point of this hack as .css files downloaded only once or twice than stored for weeks/months (if no changes in .css sizes) by all modern browsers.

Zia
03-19-2006, 06:48 AM
hmm then no need to use this att all....

HeRCuL70
03-20-2006, 11:04 PM
is it working at winodws servers?

briansol
04-24-2006, 06:16 AM
is step 3 bakwards?

I had .css in there, not .php

Hemanth
04-24-2006, 06:45 AM
Good work..

But is there any increase in performance?

Zachery
04-24-2006, 07:30 AM
Increase preformace would be removing gzip, decreasing preformance would be adding it back.

El-Gazaly
05-07-2006, 02:09 AM
This code
$cssfilename = 'clientscript/vbulletin_css/style-' . substr(md5(microtime()), 8, 8) . '-' . str_pad($styleid, 5, '0', STR_PAD_LEFT) . '.css';
is in file alreadey
and iam not editing it before

Code Monkey
05-07-2006, 03:43 AM
This is pointless since browsers cache all css and javascript when they are seperate files. It IS why you should always have them in a seperate file. Most webservers are running mod_deflate or equivilents that compress text in a way that browser can interpret. Browsers check and compare the time and date of last update for css and javascript files before downloading. So unless you have changed the css file, they will not be downloading the css in the first place.

But, do as you please.

ShiningArcanine
06-14-2006, 08:03 PM
Personally, I think gzipping css files will not add as much bandwidth savings as gzipping .php files would but more bandwidth savings and faster initial page loads make doing something like this worth it.