Skip to content

Instantly share code, notes, and snippets.

@codfish
Last active December 23, 2015 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codfish/6624919 to your computer and use it in GitHub Desktop.
Save codfish/6624919 to your computer and use it in GitHub Desktop.
Browser caching your scripts and styles intelligently
<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