1

I have a Javascript program that extracts data from a text file (just a plain *.txt file) and then displays it in a table. It works as intended except for one issue: If I update the text file where the data lives in the update does not shows up on the table. The reason is that the file is being cached by the browser.

Is there a way to force Javascript to read from the latest version of the file and not from the cached version? Again, this is not a problem with the javascript file as doing Ctrl-5 and or Shift+Ctrl+R does not works and also updating the javascript file itself behaves as expected. it is only the file where the data is in that is the problem.

To read the text file I use the Webix toolkit which uses AJAX to read the file. The reading and parsing of the text file is done via Javascript and the Webix toolkit. There is very little html in my program.

//the name of the file is dependant of an user specified input
var theURL = rossObj.store_number.store_number + "macaddress.txt ";

webix.ajax(theURL,{
    //response
    error:function(text, xml, XmlHttpRequest){
        webix.alert({ ok:"OK", type:"alert-warning", text:"could not open the following URL --> "+theURL, width:"400px"});
        return "mac_address_error";
    },
    success:function(text, xml, XmlHttpRequest){
        //parse the file;
    }
});
2
  • how are you updating the text file ? manually or via script? how are you calling it ? standard href ? can you add js to the html? Commented Dec 19, 2014 at 18:35
  • I will update my post to include more info and partial code Commented Dec 19, 2014 at 18:48

1 Answer 1

1

Try adding a random number to the end of the url as a query string, the server will ignore but the browser will treat it as a new file

var theURL = rossObj.store_number.store_number +
    "macaddress.txt?" +
    Math.floor((Math.random() * 10000) + 1);
Sign up to request clarification or add additional context in comments.

1 Comment

the browser thinks this is a different file from the one that's cached due to the query string.the server ignores the query string thinking it's for the file to deal with and just passes it over

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.