Solved

How Do you Write Your Header with GZip

Posted on 2012-04-02
9
190 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
Stressed Out?

Watch some penguins on the livecam!

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

690 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