Solved

How Do you Write Your Header with GZip

Posted on 2012-04-02
9
180 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
  • 5
  • 4
9 Comments
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 7

Author Comment

by:rgranlund
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 7

Expert Comment

by:designatedinitializer
Comment Utility
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
Comment Utility
Ohh!  I understand now!  Thank you for taking the time to explain.
0
 
LVL 7

Expert Comment

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

Author Comment

by:rgranlund
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Read about why website design really matters in today's demanding market.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now