Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 68957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:29:53+00:00 2026-05-10T19:29:53+00:00

I’ve seen a number of references to gzipping a javascript to save download time.

  • 0

I’ve seen a number of references to gzipping a javascript to save download time. But I also see a number of warnings that certain browsers do not support this.

I have two different methods at my disposal:

  1. use mod_deflate to make Apache compress JS/CSS files in a given directory through htaccess
  2. use ob_start('gzhandler') to compress a file and return it to the browser with the correct headers.

The problems with method 1 are that not all browsers support mod_deflate, and I have no clue how to write the .htaccess file to be smart enough to adjust for this.

The problem with method 2 is that there is no definitive answer about how to tell if a browser supports a gzipped script, or stylesheet, and that if it does what mime-type must be given as the content type in the header.

I need some advice. First, which method is more universally accepted by browsers? Second, how do I decay using either method to provide the uncompressed backup script? Third, would <script src='js/lib.js.gz' type='text/javascript'></script> work by itself? (It obviously wouldn’t decay.)

For the record, I’m using PHP5 with mod_deflate and full gzip creation capabilities, and my doctype is xhtml strict. Also, the javascript itself is compressed with YUI. Edit: I just went back and looked, but I have only Apache 1.3; I thought I had 2, so sorry for mentioning mod_deflate when I probably don’t have it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T19:29:53+00:00Added an answer on May 10, 2026 at 7:29 pm

    mod_deflate and php’s gzhandler both are based on zlib, so in that sense there is little difference to a browser how the content is being compressed.

    in response to your first concern, you can set module specific .htaccess info like this:

    <IfModule mod_deflate.c>   # stuff </IfModule> 

    in response to your second concern, you can detect for browser support in PHP:

    if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') ) {   ob_start('ob_gzhandler');   header('Content-Encoding: gzip'); // etc... } 

    here’s some untested .htaccess that should be able to handle negotiation of compressed vs uncompressed .js files: (source)

    <FilesMatch '\\.js.gz$'>   ForceType text/javascript   Header set Content-Encoding: gzip </FilesMatch> <FilesMatch '\\.js$'>   RewriteEngine On   RewriteCond %{HTTP_USER_AGENT} !'.*Safari.*'   RewriteCond %{HTTP:Accept-Encoding} gzip   RewriteCond %{REQUEST_FILENAME}.gz -f   RewriteRule (.*)\.js$ $1\.js.gz [L]   ForceType text/javascript </FilesMatch>     
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.