0

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]
</IfModule>

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

FileETag none
Mark Henderson
  • 68,316
  • 31
  • 175
  • 255
user71793
  • 1
  • 1

3 Answers3

1

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

Pritam Barhate
  • 129
  • 1
  • 8
0

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

Paul
  • 779
  • 1
  • 9
  • 18
  • 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 03:38
  • RewriteCond %{REQUEST_FILENAME}.gz -s RewriteRule ^(.+) $1.gz RewriteRule \.js\.gz$ - [T=text/javascript] – user71793 Feb 23 '11 at 03: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
0

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
DIRECTORIES="/var/www/nginx_default/*"

for currentdir in $DIRECTORIES
do
   for extension in $FILETYPES
   do
      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' \;
   done
done

the link to the original article is here: http://wiki.linuxwall.info/doku.php/en:ressources:dossiers:nginx:nginx_performance_tuning

Julien Vehent
  • 2,927
  • 18
  • 26