0

Preventing caching of text file.

Scenario: I have a text file in which I store the state of check-boxes i.e. whether they are checked or unchecked and I'm using a JavaScript to check the boxes according to the information/data in the text file. Whenever I a box is checked/unchecked the data in text file gets updated accordingly using php script. Whenever the page is reloaded the JavaScript check the boxes according to the last updated values. Problem: Due to the fact that the text file gets cached, the JavaScript check the boxes according to this cached file rather than the updated one. So is there any way to prevent caching of the text file? I've tried the meta tag method, <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> <META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 22 Jul 2002 11:12:01 GMT" but this method didn't worked for me.

17th Dec 2018, 5:20 PM
Mayank Dhillon
Mayank Dhillon - avatar
3 Réponses
+ 3
Lexus Collins is going the right direction, using controls within the protocol. You can also use a cachebuster: http://example.com/resource.txt?cachebuster=some_random_value_like_a_GUID These are also cached so the value has to change on each request. Ref: "What is Cache Busting?" https://www.keycdn.com/support/what-is-cache-busting
17th Dec 2018, 8:45 PM
Kirk Schafer
Kirk Schafer - avatar
0
Lexus Collins and Kirk Schafer Thanks for the answer. I tried all the methods you both mentioned but the one that really worked for me was Lexus Collins method to read data from php itself. Though the cache busting method was great for one time update but php method felt more dynamic. to me. Thanks again.
18th Dec 2018, 4:20 AM
Mayank Dhillon
Mayank Dhillon - avatar