Drupal: .htaccess Access Deny
August 21, 2014 – 7:59 am | No Comment

In this article I will tell how to forbid access to certain resources for some clients. The instructions will include descriptions of different directives.

Read the full story »
CSS Templates

Contain reviews and news about CSS Templates.

Freebies

Contain freebies such as icons, graphics, headers and images for your websites.

Fun Stuff

Contains other fun stuff for entertainment or interesting site showcase.

How-To

Contain technical elaborations on some specific workarounds or common tweak.

Joomla Templates

Contains reviews and news about Joomla templates.

Home » How-To

Drupal: Traffic Compression

Submitted by on July 12, 2010 – 10:03 amNo Comment

 

This article tells how to speed-up CSS and JS files uploading by means of compression on server and passing compressed copy to browser.

Solutions

  • Automated compression by server
  • Create archive for every JS/CSS file and send it instead of unpacked files manually.
  • Using mod_deflate module
  • Using nginx web-server for traffic compression
  • Automated compression by server

    You should insert the following code to .htaccess file:

    <IfModule mod_gzip.c>
          mod_gzip_on                   Yes
          mod_gzip_item_include         file       \.js$
          mod_gzip_item_include         file       \.css$
    </IfModule>

    Create archive for every JS/CSS file and send it nstead of unpacked files manually

    You should archive all these files manually and upload them to the server. It is a fag but number of files cannot approach infinity… And there is no server loading for creation packed file copy.

    Add *.js files to *.js.gz archive and upload to server to the same folder where original JS file is located.

    Insert the following code to .htaccess file (in the site root) right after RewriteEngine on:

        RewriteRule ^(.*\.js\.gz)$ – [L]
        RewriteCond %{HTTP:Accept-Encoding} gzip
        RewriteCond %{REQUEST_FILENAME}.gz -f
        RewriteRule ^(.*)$ $1.gz

    Checking if it works correctly

    Load a page in browser and view request headers:

    • Response Headers
    • Date Wed, 19 Mar 2008 12:32:09 GMT
    • Server Apache
    • Cache-Control max-age=1209600
    • Expires Wed, 02 Apr 2008 12:32:09 GMT
    • Last-Modified Wed, 19 Mar 2008 12:31:38 GMT
    • Etag "bdcf97-87d-47e107aa"
    • Accept-Ranges bytes
    • Content-Length 2173
    • Connection close
    • Content-Type application/x-gzip
    • Content-Encoding gzip

    Size of the received file should be smaller…

    Operational principle

    mod_rewrite decides what file (compressed or no) is to be sent to the client:

    Operational principle:
    If compressed copy javascript.js.gz  is be located near javascript.js file and request contains a note that client maintains gzip-encoding then client gets compressed copy. If compression isn’t maintained or there is no compressed file, client gets original file as a response.

    As a result, server traffic and server loading are decreased. The same thing can be applied for CSS.

    Using mod_deflate

    There is a suggestion to deliver mod_deflate in standard apache 2.x ;)

    Using nginx web-server for traffic compression

    You can also use nginx. It can compress a folder immediately or perform your request: send compressed files instead of originals.

    Leave a comment!

    Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

    Be nice. Keep it clean. Stay on topic. No spam.

    You can use these tags:
    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.