Caching specific Javascript and CSS files

前端 未结 3 1226
一生所求
一生所求 2020-11-28 10:32

How can I cache a few specific JavaScript & CSS files. I found advice from this site to put this in my .htaccess file

AddOutputFilter DEFLAT         


        
3条回答
  •  半阙折子戏
    2020-11-28 10:53

    1. AddOutputFilter DEFLATE: output is compressed(usually gzip) before sent to server in this case css & js your css and js.
    2. ExpiresActive On: Sets Expires and cache control headers to On
    3. ExpiresByType: Set the expire rule for the content type in this case application/x-javascript to a month A2592000 => 24 * 3600 * 30 its in ms.

    I would recommend to instead of handling specific js via .htaccess you should add a revisions number to your js files, ala:

    Then when you update your files just update the rev number. And your clients will automatically be served the new files.

    Resources:

    • http://httpd.apache.org/docs/2.0/mod/mod_deflate.html
    • http://httpd.apache.org/docs/2.0/mod/mod_expires.html
    • http://html5boilerplate.com/docs/htaccess/

提交回复
热议问题