Using .htaccess, I install a PHP handler for all of my .css and js to output user agent based code:
AddHandler application/x-httpd-php .css .js
For instance:
<?PHP if ($CurrentBrowser == 'msie') { ?> .bind('selectstart', function(event) { ... }) <?PHP } ?>
Thus, my code files are dynamically created, but can be considered static files. This is because, as soon as they were compiled for the first time, browsers can return them from the cache and reuse them until I change their contents. This is why I use fingerprints / versions and for a long time on them:
[INDEX.PHP] <script type="application/javascript" src="<?PHP echo GetVersionedFile('/script.js'); ?>"></script> <script type="application/javascript" src="/script.1316108341.js"></script> [.HTACCESS] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule "^(.+)\.(\d+)\.(css|js)$" $1.$3 [L]
The problem is that these files, even if I send them with the correct header, are never cached by any browser (I never get the code 304, always 200). This is my server response log:
[CHROME] Request URL:http:
What could be the problem? How can I force cache these files? Thank you very much!
source share