Reputation: 1586
I have some local files, they are filled with pure json text.
I have a php script that serves them. I use php because it allows me to serve them in a zipped format, depending on the capabilities specified in the request. This is much leaner.
The php does this by getting an url parameter, fetching the file, and dumping its (zipped) output on the stream.
Still, now I'm wondering how to cache these files. How can I specify in the php code that the file will not have changed, so that the client can use a cached version of that response?
Or is there an option to serve these files statically in a zipped manner so caching is performed by the static web server? (I'm using httpd).
Upvotes: 2
Views: 438
Reputation: 684
Apache 1.3 uses mod_gzip while Apache 2.x uses mod_deflate. You can compress you content without using php script dpending upon type of request. Use following lines in your apache config to deflate/gzip static content:
AddOutputFilterByType DEFLATE application/javascript
You can also add far future expire header for static content using apache. You do not need to use php script for that. Add this line to your apache config for static content:
ExpiresActive On
ExpiresDefault "access plus 4 hours"
ExpiresByType application/javascript "access plus 1 year"
You can also add it to a .htaccess file in your static content directory
Upvotes: 2
Reputation: 1130
You can use expires header and use a distant future date:
<?php
header("Expires: Fri, 01 Jan 2020 00:00:00 GMT");
Upvotes: 1