Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

my site is running IPB 3.1.4 and I want to pre-compress my .js files. I have ssh root access and need the command to gzip the js directory and the code for htaccess.

My htaccess:

Options -Indexes

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

<FilesMatch "\.(ico|flv|jpe?g|png|gif|js|css|swf)$">
ExpiresActive On
ExpiresDefault "access plus 1 month"

FileETag none
share|improve this question

If you are running your own VPS or dedicated server, then mod_deflate for Apache can help you to solve this.

share|improve this answer

Might the bash script in an answer to this question help?

share|improve this answer
Yeah I found that and it work. Also I have added this to my htaccess file and it seems to work, but now I have another problem. People viewing my site without gzip enabled in their browsers don't load the javascript. – user71793 Feb 23 '11 at 3:38
RewriteCond %{REQUEST_FILENAME}.gz -s RewriteRule ^(.+) $1.gz RewriteRule \.js\.gz$ - [T=text/javascript] – user71793 Feb 23 '11 at 3:39
you need to keep both files (gzipped and original) next to each other and make sure, if a client does not announce "Accept-Encoding: gzip", the server will send it the non gzipped version. – Julien Vehent Feb 23 '11 at 16:09

I don't have the htaccess, but since I did that on Nginx some time ago, I can at least give you the bash script. I scans a directory (and its subdirectories) and gzip the listed filetypes. It also regenerates gzip when the source is more recent.

#! /bin/bash
# jve - 2011
# this script checks a list of directories for a list of extensions and
# generated gzipped versions of the files that are found
# if the modification date of a file is newer than its gzipped version
# then the gzip file is regenerated

#     specify a filetype like *.css or a filename like index.html
# leave one space between each entry
FILETYPES="*.css *.jpg *.jpeg *.gif *.png *.js *.html"

# specify a list of directories to check recursively

for currentdir in $DIRECTORIES
   for extension in $FILETYPES
      find $currentdir -iname $extension -exec bash -c 'PLAINFILE={};GZIPPEDFILE={}.gz; \
         if [ -e $GZIPPEDFILE ]; \
         then   if [ `stat --printf=%Y $PLAINFILE` -gt `stat --printf=%Y $GZIPPEDFILE` ]; \
                then    echo "$GZIPPEDFILE outdated, regenerating"; \
                        gzip -9 -f -c $PLAINFILE > $GZIPPEDFILE; \
                 fi; \
         else echo "$GZIPPEDFILE is missing, creating it"; \
              gzip -9 -c $PLAINFILE > $GZIPPEDFILE; \
         fi' \;

the link to the original article is here:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.