0

This should be a simple problem, I just can't seem to stumble upon the right answer:

So I have a site in HTML with many pages that all link to the newest one, so I created a simple JavaScript function in a separate file:

function newest() {
    window.location = "http://xxxxxxxxxx.xxx/6.html";
}

With the line:

 < script type="text/javascript" src="javascript.js">< /script>

In my HTML document.

So I can update the number every time a new page is posted. The problem is that when I post a new one, the code doesn't refresh from the user side until you delete the cookies (if I replace it with 7, it will still redirect to 6).

Sorry if it is a stupid question, but everything I have looked up seems way off topic.

2
  • Did you title your file javascript.js? Commented Jan 1, 2014 at 4:13
  • Yes, it seems to work fine initially, but doesn't modify due to some issue with cookies overwriting it or something (I'm not very knowledgable with that sort of thing at all) Commented Jan 1, 2014 at 4:26

3 Answers 3

1

The cache expects your javascript to me immutable so unless you can include the file name external to your javascript then this path is not going to work... How about just creating a 'latest.html' page that is either a file system link to the original or else redirects to the latest version.

Sign up to request clarification or add additional context in comments.

2 Comments

Ended up going with this method with this code in the head of my redirection page (seems to work fine, thank you.) (Not sure how to format on this site, sorry): < meta http-equiv="refresh" content="0"; URL="xxxxxxxxx.xxx/6.html" /> < script type="text/javascript"> window.location.href = "xxxxxxxx.xxx/6.html" < /script>
No problem, for future reference to format code in a comment enclose the code in 'back ticks' (the alternate function of the ~ key)
1

A simple client side solution would be to inject the script with different version attributes appended to it.

So HTML page can contain a script like :

var script = d.createElement('script');
script.type = 'text/javascript';
script.src = 'http://xxxxxxxxxx.xxx/javascript.js?v=' + Math.random();
d.getElementsByTagName('head')[0].appendChild(script);

Notice the random number?

where javascript.js is the one having your code:

function newest() {
    window.location = "http://xxxxxxxxxx.xxx/6.html";
}

Comments

0

You can turn off the caching of the resources (javascript files) on the client machine by adding the instructions in your code for the web browser, not to cache. Refer to this link for how to turn off caching for your webpage.

Comments

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.