最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Make window.location.href load page from Server instead from browser cache - Stack Overflow

programmeradmin1浏览0评论

I am making a redirect using window.location.href.

But what it does, it simply fetches old page (not showing the newly added item) that was previously in borwser's cache.

I want it to fetch every think from server, just like we use true parameter in document.location.reload(true) to load a fresh copy of page from server.

I am making a redirect using window.location.href.

But what it does, it simply fetches old page (not showing the newly added item) that was previously in borwser's cache.

I want it to fetch every think from server, just like we use true parameter in document.location.reload(true) to load a fresh copy of page from server.

Share Improve this question edited Apr 4, 2023 at 6:19 Umair Ayub asked Jul 23, 2016 at 18:19 Umair AyubUmair Ayub 21.5k14 gold badges82 silver badges154 bronze badges 3
  • can you show your code here? – Syed Aqeel Commented Jul 23, 2016 at 18:21
  • its simply window.location.href = "http://www.mywebsite./products" – Umair Ayub Commented Jul 23, 2016 at 18:22
  • if you think that it loads cached pages instead of new then you should try in private browsing to see the new result. other condition I can't examine what are you asking about – Syed Aqeel Commented Jul 23, 2016 at 18:26
Add a ment  | 

2 Answers 2

Reset to default 7

You can use this:

window.location.href = "http://www.mywebsite./products?t="+ (new Date().getTime());

Or:

window.location.href = "http://www.mywebsite./products?t="+ Math.random();

You can use this for any websites:

window.location.href = window.location.href.split('?')[0] + '?cacheBuster=' + new Date().getTime();

发布评论

评论列表(0)

  1. 暂无评论