a webmaster learning community
     Home    Register     Search      Help      Login    
FrontPage Alternative
Sponsors

Hosting from $3.99 per month!

Shopping Cart Software
Ecommerce software integrated into Frontpage, Dreamweaver and Golive templates. No monthly fees and available in ASP and PHP versions. dd

Website Templates
We also have a wide selection of Dreamweaver, Expression Web and Frontpage templates as well as webmaster tools and CSS layouts.

Frontpage website templates
Creative Website Templates for FrontPage, Dreamweaver, Flash, SwishMax

Search Forums
 

Advanced search
Recent Posts

 Todays Posts
 Most Active posts
 Posts since last visit
 My Recent Posts
 Mark posts read

 

Compress your pages! (Average up to 80%)

 
View related threads: (in this forum | in all forums)

Logged in as: Guest
Users viewing this topic: none
Printable Version 

All Forums >> Web Development >> General Web Development >> Compress your pages! (Average up to 80%)
Page: [1]
 
BobbyDouglas

 

Posts: 5479
Joined: 5/15/2003
From: Arizona
Status: offline

 
Compress your pages! (Average up to 80%) - 4/29/2005 17:59:39   
Here is a neat trick that will compress your pages. This compresses text only, and does not include images/flash/etc. This saves bandwith by sending compressed pages to the user, and is very easy on the server.

This has only been tested on Linux/Unix servers. If you are Windows, there is a service that offers Compression for Windows.

FAQ (Detailed page explaining the process of compression)

Q. What is compression?
A. Compression is similar to programs such as WinZip, and WinRar that compress files into .zip format. However in this article, compression is done much faster.
Q. What exactly happens?
A. The server (place the website is on), receives a request for the page (Someone comes along and says, hey give me that file!), after it receives the request, it compresses the file, and then sends the compressed file. The browser (of the person who requested the file) will automatically unzip the compressed file.
Q. Will this slow down my computer?
A. No.
Q. How do I tell if this will work on my browser?
A. All of the most common browser do this automatically. If you are not sure if your browser supports this, please ask below. You should not have to modify any settings, or make any changes at all in order for this to work.
Q. How come everyone doesnt do this?
A. Most people do not know of its ability, and are not educated on its' use.
Q. Will this hurt my web server?
A. If your server is properly maintained, there should not be any issues at all. There is a slight increase in processor usage, but with the amount of banwidth being saved, this is a small price to pay.

Overview
- How to check if this will work on your website?
- How to implement it into my site (two options)
- How to test the compression results

Part 1) How to check if this will work on your website?
We first must find out if this will work on your server. This is done by finding out if the zlib module is installed. Either ask your host, or do the following:
1.1 - Create a file named phpinfo.php with the follow code:
<?php
phpinfo();
?>

1.2 - Open the file on your sever (suggestion: hit Control+F and enter the text zlib to search for the table), you will be looking for a table that contains information similar to this:
quote:

ZLib support: enabled
Compiled Version: 1.1.4
Linked Version: 1.1.4

1.3 - If this is shown on the page, you can continue below. If this is not installed, contact your host and ask them to install the module. You can link them to this thread, or tell them the zlib module needs to be installed.

Part 2) How to implement it into my site (two ways)
You can use code at the beginning of each PHP page, or use .htaccess.
----------------------------------------------------------------------------------------
Option 1) Adding the correct code to each .php page
----------------------------------------------------------------------------------------
2.1 - The best option is to place specific code at the beginning of each .php page. You can activate the compression by the following code:
<?php
ob_start( 'ob_gzhandler' );
?>


Your page should look something like this:
<?php
ob_start( 'ob_gzhandler' );
?>
<html>
<head>
</head>
<body>
<p>This web page is now COMPRESSED!</p>
</body>
</html>

2.2 - Save your page and continue with Par 3 to test the compression.
----------------------------------------------------------------------------------------
Option 2) Using .htaccess to compress your pages
----------------------------------------------------------------------------------------
2.3 - The other method is easier to use, and only requires editing of a single file. Begin by logging into your hosting account and going to a file manager type section (details on how to do this will be given by your host- if they are unaware of what you want to do, ask them this: "How do I create and edit a .htaccess file?")
2.4 - Open your .htaccess file, if you do not have one to open, simply create one by naming a file .htaccess. You must do this from your control panel, as it usually does not work if you create the file from your computer, and upload it like that.
2.5 - At the very top of your .htaccess file (if you use FrontPage Serer Extensions, there will be info regarding that inside this file, do not delete or edit it, but simple place your cursor before this line, and hit return to make a new line). You need to add this code:
php_flag zlib.output_compression On

2.6 - Save your .htaccess file.
2.7 - Visit your .php pages and make sure no errors exists.
Note: If you are running software that already uses this method, an error will be created when you are trying to use .htaccess on pages that already are compressed. You may not run both methods above.

Part 3) How to test the compression results
There are a few websites that will allow you to rate the level of compression. One that I have used in the past is PipeBoost.

This will tell you how much you are saving by using the information in Step 2. Also note that both methods above will produce the same end result.


Information and pictures are posted at PHP Page Compression

< Message edited by BobbyDouglas -- 5/3/2005 19:38:55 >


_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge
anderskorte

 

Posts: 545
Joined: 2/20/2005
From: Finland
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/2/2005 14:18:11   
Hey that's pretty hot.

Part 1 is trivial, probably all Linux boxes have zlib installed, it's a must.

But how does it work in practice...? It sends it compressed to the browser, but how come the browser knows to decompress it? Since when has IE done gunzip? I get kind of lost halfway reading that.

(in reply to BobbyDouglas)
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/2/2005 14:22:29   
Most browsers support gzip compression, so if unsupported, only normal content is sent after http header negotiation

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to anderskorte)
BobbyDouglas

 

Posts: 5479
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/2/2005 15:27:45   
Yay! Someone replied.

quote:

Part 1 is trivial, probably all Linux boxes have zlib installed, it's a must.

- Most have it installed, but I believe the version needs to be .4 or higher. I haven't tested on previous versions of zlib, just because I don't have a test box.

quote:

It sends it compressed to the browser, but how come the browser knows to decompress it? Since when has IE done gunzip? I get kind of lost halfway reading that.

- It is a standard feature for any browser. Any browser that doesn't include it, isn't a brower I know about! Mozilla, IE, Opera, etc... all support this.

I will see if I can clear it up a bit. Anything else that you didn't quite understand?

_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to Spooky)
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/2/2005 15:41:07   
quote:

It sends it compressed to the browser

The point is - it doesnt, the server maintains 2 versions and only sends the version the browser can handle.

Another Windows option, is httpzip from www.port80software.com

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to BobbyDouglas)
BobbyDouglas

 

Posts: 5479
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/2/2005 16:16:11   
Right, it only sends the compressed version when it can to the browser....

_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to Spooky)
BobbyDouglas

 

Posts: 5479
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/2/2005 21:37:23   
I talked to one of my sys admins about it, he said that the zlib creates the file on the fly, and that mmcache is what stores the compressed files inside the /tmp folder. I don't think he is 100% sure though. He also mentioned that zlib always sends out the compressed file, instead of the normal file.

Like I said, not sure if the above statement is accurate, but it made me think about how it works. Spooky, can you verify what I said above it correct/incorrect? It would be really interesting to find out for sure what it does.


_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to BobbyDouglas)
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 0:05:59   
"Can I explain"
From a server perspective, no. Its magic :)

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to BobbyDouglas)
BobbyDouglas

 

Posts: 5479
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 1:07:12   
Ah, but you were right. It basically just sends out the one the browser requests. At least that's what I gather from the article.

Either way, it is FAST!!!!


_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to Spooky)
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 2:06:33   
An example, when running httpzip through our server here, pages that weighed in previously at 60-70k pure html are reduced to 10-20k
So, huge gains can be made.

IIS 6 has good built in compression, but we are on 5 :)

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to BobbyDouglas)
jaybee

 

Posts: 14207
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 3:17:29   
OK, very early in the morning here and I just tried to read the link info and my head nearly exploded.

What exactly does GZip zip? Is it just removing all the whitespace from code pages or is it compressing pictures etc as well?

I don't want to spend ages faffing around only to find that I get little compression over a whitespace stripper.


_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to Spooky)
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 6:52:23   
No, its about applying a compression alogrithm to the page that can be interpreted by the browser.
Some products will also strip whitespace and increase the savings moreso.

However, compression will give you faster easier savings in page size than css and thrifty coding will ever give you.

Theres simply not too many reasons not to use it.
If you pay for bandwidth, then enabling compresion will bring in instant savings, sometimes to the tune of 30% or more.
Whatever you have, its a better experience for the end user when the page is rendered faster.

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to jaybee)
jaybee

 

Posts: 14207
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 8:05:03   
quote:

Theres simply not too many reasons not to use it


And those not reasons for not are? :)


_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to Spooky)
jaybee

 

Posts: 14207
Joined: 10/7/2003
From: Berkshire, UK
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 8:13:25   
quote:

<?php
ob_start( 'ob_gzhandler' );
?>


Before or after the Doctype?


_____________________________

If it ain't broke..... fix it until it is.
:)

:)
GAWDS
Now where did I put that Doctype?

(in reply to jaybee)
BobbyDouglas

 

Posts: 5479
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 11:57:52   
quote:

An example, when running httpzip through our server here, pages that weighed in previously at 60-70k pure html are reduced to 10-20k

- But there are not duplicates of files, right? Meaning they are not stored in a temp dir until they are requested.

quote:

However, compression will give you faster easier savings in page size than css and thrifty coding will ever give you.

- I took a site the other day, made it in xhtml/css (not 100% great coding, but still good enough), then put on the zlib, and the page loads sooooooooo fast now. Mix this up with a speedy server in One Whilshire, and you have yourself a screamin fast page.

quote:

Before or after the Doctype?

- It goes before EVERYTHING. So before the Doctype too. If your page is already php, then you can simply add ob_start( 'ob_gzhandler' ); to the code. But you can still use the exact code posted in my first post, and it will work.

quote:

And those not reasons for not are?

- It requires a little more CPU usage, if you are on a VPS, it might not be a good idea to run a forum with compression on, if the forum gets high traffic. VPS are already slow enough with high traffic forums. That and the fact it requires a specific zlib module to be installed, are about the only reason one wouldn't use it.

_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to jaybee)
rdouglass

 

Posts: 9280
From: Biddeford, ME USA
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 14:41:23   
quote:

IIS 6 has good built in compression,


So Spooky, any ideas as to whether combining compression features is beneficial or will it cause problems with IIS 6 caching?  or does it cache the compressed pages as well?

I'm not very familiar with the built-in compression of IIS 6.:)

_____________________________

Don't take you're eye off your final destination.

ASP Checkbox Function Tutorial.

(in reply to Spooky)
bobby

 

Posts: 11399
Joined: 8/15/1969
From: Seattle WA USA
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 19:04:22   
Dang it, Bobby... now I'm gonna have to put together another test box at home.

:)


_____________________________

In order to remove a wall you must first remove the Windows®


:)

(in reply to rdouglass)
Spooky

 

Posts: 26617
Joined: 11/11/1998
From: Middle Earth
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 19:08:05   
Some more reading perhaps?

http://www.seoconsultants.com/articles/1000/http-compression.asp

_____________________________

If you arent part of the solution, then there is good money to be made prolonging the problem

§þ:)


(in reply to bobby)
BobbyDouglas

 

Posts: 5479
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/3/2005 19:27:48   
Very nice find Spooky. I will have to add that to the first post.

quote:

any ideas as to whether combining compression features is beneficial or will it cause problems with IIS 6 caching?  or does it cache the compressed pages as well?

- I know that combinations are used on Unix/Linux without problems (assuming you are configuring it correctly). mmcache and the zlib can really speed up forums. I noticed a forum that just started to use mmcache, I can't believe how fast it is.

Spooky, if you notice anything really misleading in the 1st post, feel free to edit it.


< Message edited by BobbyDouglas -- 5/3/2005 19:42:53 >


_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to Spooky)
anderskorte

 

Posts: 545
Joined: 2/20/2005
From: Finland
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/4/2005 12:54:11   
And also this wonderful method was brought to you by the wonderful world of Unix.

Gosh, you just gotta love that system!

(in reply to BobbyDouglas)
BobbyDouglas

 

Posts: 5479
Joined: 5/15/2003
From: Arizona
Status: offline

 
RE: Compress your pages! (Average up to 80%) - 5/4/2005 13:31:49   
Hey! Windows has it too...

Just send me $10,000 and I will install the version for Windows :)

_____________________________

Arizona Web Design - Mr Bobs Web Design in Arizona
The Arizona Web Hosting Challenge

(in reply to anderskorte)
Page:   [1]
OutFront Discoveries

All Forums >> Web Development >> General Web Development >> Compress your pages! (Average up to 80%)
Page: [1]
Jump to: 1





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts