I need to set up a specific expire header to json files, much much lower than the rest of files. Can I do this in W3TV? I couldn’t find a way.
The default of 31536000 seconds is ok for all other file types. But I use the JSON REST API to deliver data to an AngularJS+Cordova App, and was having a problem with content not being updated. We figured out that It was the json expire header when we manually configured 300 seconds, problem is W3 TC constantly overrides this change.
Is there a way to tell W3 TC to use a lower expire header for json files? Or a way manually enter a value that’s not overridden by W3TC?
The only idea I’ve come up with is to rewrite the json expire header rule at the bottom of .htaccess, but I don’t know if this is going to prevent W3TC to edit or erase it. Also, having a repeated rule seams just plain wrong from the begging.
Or is there any way to tell Angular to re download the json file even if the cache header tells it to keep it for a year?
What do you think?
Thanks!
FG
Add a random property to the end of the URL to fetch the JSON file. This is what jQuery does to ensure that the cache is not used for JSON requests.
Assume your file URL is
http://example.com/myfile.json
, then you would fetch it withhttp://example.com/myfile.json?__random=1
the first time andhttp://example.com/myfile.json?__random=2
the second time etc. of course you should use totally random numbers instead of 1, 2 etc.W3TC offers 3 groups of header policies to manage for user agent (browser) caching. The third group on the browser cache settings page has an “Other” section where the headers available there would be applied to the json response from WP unless there’s a bug or implementation that prevents this behavior from occurring. W3TC sets the directives for the nginx or apache web server to apply the headers specified on this page and there are ways that this policy could fail to be applied, however the intent is as indicated.