Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I actually serve my JS files from a PHP script. Not because of this issue but so I can control the expires header and caching. The general model is:</p> <ul> <li>The URL is something like /script/blah.1234567890.js;</li> <li>That URL is generated from the mtime of the blah.js file;</li> <li>That URL is sent to a js.php script via a rewrite rule in the .htaccess;</li> <li>The script checks the mtime passed in. If its newer than the mtime of the cached version it generates a new cached version from all my JS files (that are collated into a single file and then minified with JSMin);</li> <li>If the mtime is not newer than the script, the cached version is simply served;</li> <li>In all cases the content is set to expire a year from now.</li> </ul> <p>The timestamp in the URL allows for refreshing the script file.</p> <p>Now how does this relate to gzipping? Simple. At the top of my js.php script is:</p> <pre><code>ob_start("ob_gzhandler") </code></pre> <p>which turns on gzip compression if the client supports it (as well as using output buffering).</p> <p>It works really really.</p> <p>Try and limit yourself to exactly one JS and one CSS file. Combine them if necessary. I do the same trick with CSS files too (no minification of course).</p> <p>The advantage of this solution is it only relies on mod_rewrite being enabled. No other extension is necessary (ob_gzhandler is a standard part of PHP). Plus a script is necessary to combine the files (unless you do that as part of a build process but I find this a bit more tedious).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload