Posted By

ashsa on 02/03/11


Tagged

cache


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

hebertialmeida
vitor_np
gecube


cache control with file modification date


 / Published in: PHP
 

  1. <script type="text/javascript" src="file.js?<?php echo filemtime('file.js'); ?>"></script>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: iroybot on November 8, 2011

This is exactly how I did this for quite a while now. Today I think there's better ways to do this: Since modern websites (should) use some sort of JS compression (Minify, Dojo Compressor, Google Closure, etc.) you could as well update the link to the JS file in your HTML document whenever you run the compiler. Thus you can move away this freshness-determination from the Frontend and do that server side. Usually, I use jQuery with some dozen plugins, so I save a dozen file accesses upon request.

You need to login to post a comment.