location.reload

location.reload

本来是不想写这个的,但看到在用中文搜索得到的结果时,很是不满意。你基本得到是location.reload()是从浏览器缓存中读取。这样的答案有时真是莫名。很直接的理解成从IE缓存读取,及时原页面有更新也是这样。

最初的理解是这样,结果很自然的想到,使用location.reload(true)来重新加载页面(强制获取所有页面的元素)。而且搜索到的结果很多直接回答“使用location.reload(true)就可以解决问题了”。理论上这样是没问题的,但在实际的应用环境中,如果这个操作是经常使用的,这样的用法很明显的是降低服务器性能的,对于访问量高的网站。嘿嘿,你这样使用,是给服务器制造麻烦。

通过location.reload(false)的Http请求状况(pic1)

locationfalse

通过location.reload(true)的Http请求状况(pic2)

locationtrue

从PIC2中就很明显的看出所有的请求都是200,这样的结果就是服务器重新返回所有的数据(特别是当这个页面图片很多的时候)。而这种重新操作是没有必要的。性能问题就很明显了。

下面列出location.relaod的具体解释,个人认为这是比较标准的啦

Thereload()method of the Location object reloads the document that is currently displayed in the window of the Location object. When called with no arguments, or with the argumentfalse, it uses theIf-Modified-SinceHTTP header to determine whether the document has changed on the web server. If it has, it reloads the document from the server, and if not, it reloads the document from the cache. This is is the same action that occurs when the user clicks on Navigator'sReloadbutton.

Whenreload()is called with the argumenttrue, then it will always bypass the cache and reload the document from the server, regardless of the last-modified time of the document. This is the same action that occurs when the user shift-clicks on Navigator'sReloadbutton

其实这里还可以简单的理解成(IE浏览器)

location.reload() => F5刷新

location.relaod(true) => Ctrl + F5 刷新

这里顺便提一下:location.href 和 location.replace

这两个也可以达到刷新页面的效果,但是不同于locatio.reload.具体大家可以看我最后列举的参考资料.

location.replace 没有历史记录,就是浏览器的前进后退按钮失效(PS:我们部落里的帖子不能前进后退功能失效可能是这个原因)

location.href       有历史记录,相当于一个页面的链接跳转。所以不会有"post"数据的问题。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值