Last active
December 23, 2015 10:59
-
-
Save codfish/6624919 to your computer and use it in GitHub Desktop.
Browser caching your scripts and styles intelligently
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" type="text/css" href="/css/main.<?php echo filemtime('/path/to/css/main.css'); ?>.css" /> | |
<script language="javascript" src="/js/common.<?php echo filemtime('/path/to/js/common.js'); ?>.js"> | |
</script> | |
# Add a rewrite in apache | |
RewriteRule ^(css|js)/(.*)\.[0-9]+\.(.*)$ /$1/$2.$3 [L] | |
# nginx | |
rewrite ^(css|js)/(.*)\.[0-9]+\.(.*)$ /$1/$2.$3 last; | |
# not using php? use whatever language to generate a new unique number, preferably based on the time the file was last modified |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment