Solved

How Do you Write Your Header with GZip

Posted on 2012-04-02
9
186 Views
Last Modified: 2012-04-06
How do you write a link in the head of a document as a GZip file?

Specifically your CSS files/
0
Comment
Question by:rgranlund
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 500 total points
ID: 37798564
I assume what you want is for your server to compress the data it send to the users' browsers.
For this, you will have to enable gzip compression in your server.
How this is done varies from server to server, and from server version to server version.
This is what you place in the .htaccess file in the server folder you want to active, in case you are using Apache 1.3:
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

Open in new window


And this is for Apache 2:
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
# Don’t compress
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
#Dealing with proxy servers
<IfModule mod_headers.c>
Header append Vary User-Agent
</IfModule>
</IfModule>

Open in new window

0
 
LVL 7

Author Comment

by:rgranlund
ID: 37798787
I'm sorry, I should have been more clear:  How do you write it in the HEAD of your website document?
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37800171
You don't.
HTML is text that reaches the browser, which in turn parses it.
Compression is provided by the server, as per my answer above.
You can check this faq from Yahoo. It gives you a simple explanation and more hints on how to speed up your site:
http://developer.yahoo.com/performance/rules.html
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 7

Author Comment

by:rgranlund
ID: 37802018
Yes, YSlow indicates that I need to gzip certain files in the head of my document.  I am not sure how to do that.
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37802427
You're confusing the <head> element of an HTML page with the HTTP response headers sent from the server.
If your server is Apache, then take the proper piece of code I posted above and stick it inside an .htacces file in your document root (the folder named 'public_html', or 'http_docs').
0
 
LVL 7

Author Comment

by:rgranlund
ID: 37802494
Ohh!  I understand now!  Thank you for taking the time to explain.
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37802507
notice I made a typo in my last remark: it is ".htaccess"
0
 
LVL 7

Author Comment

by:rgranlund
ID: 37802598
Can you use both in your .htaccess?

OR what about the following:
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
0
 
LVL 7

Expert Comment

by:designatedinitializer
ID: 37802712
This is a more thorough solution, courtesy of Apache manual (http://httpd.apache.org/docs/2.0/mod/mod_deflate.html):

<Location />
# Insert filter
SetOutputFilter DEFLATE

# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine
# BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
# the above regex won't work. You can use the following
# workaround to get the desired effect:
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

# Don't compress images
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</Location>

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Open dialog with server side controls in it 3 46
MediaWiki - Move a site 4 31
javascript form - error when hitting enter 3 28
.CSS HTML Help 3 23
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question