如何预gzip静态JS

我的网站正在运行IPB 3.1.4,我想预先压缩我的.js文件。 我有ssh根访问,需要命令gzip的js目录和htaccess的代码。

我的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 

如果您正在运行自己的VPS或专用服务器,那么Apache的mod_deflate可以帮助您解决这个问题。

可能在这个问题的答案bash脚本帮助?

我没有htaccess,但是由于我前段时间在Nginx上做了这个,我至less可以给你bash脚本。 我扫描一个目录(及其子目录)并gzip列出的文件types。 当源更新时,它也会重新生成gzip。

 #! /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 

链接到原来的文章是在这里: http : //wiki.linuxwall.info/doku.php/en : ressources : dossiers : nginx : nginx_performance_tuning