简体   繁体   English

Chrome历史记录API问题

[英]Chrome History API problems

I'm having problems with a website is Chrome. 我的网站问题是Chrome。

Most of the site uses ajax/xmlhttprequest for pages loads and the history API to enable the back button. 大多数网站使用ajax / xmlhttprequest进行页面加载,使用历史API来启用后退按钮。 Only the page content is changing with the request, the menu etc are never reloaded. 只有页面内容随请求而变化,菜单等永远不会重新加载。 This just re-reuns the ajax request for the previous page. 这只是重新重新启动上一页的ajax请求。 This all works fine until someone clicks the back button after viewing the blog. 这一切都正常,直到有人在查看博客后单击后退按钮。 The blog isn't loaded with ajax, it's just a standard link. 博客没有加载ajax,它只是一个标准链接。

In Firefox if I go to the blog then press back the site loads correctly. 在Firefox中,如果我访问博客,请按回网站正确加载。 The main page with the navigation loaded and so is the page to be viewed within it. 加载导航的主页面是要在其中查看的页面。

In Chrome however if I press the back button from the blog the 'outer' page isn't loaded, only the contents of the ajax request is. 在Chrome中,如果我按下博客中的后退按钮,则不会加载“外部”页面,只会显示ajax请求的内容。 You may need to view it to fully understand. 您可能需要查看它才能完全理解。

Is this a bug in Chrome or my work? 这是Chrome或我工作中的错误吗? It seems I can't return to a page that was partially loaded using xmlhttprequest as only the requested item is loaded. 似乎我无法返回到使用xmlhttprequest部分加载的页面,因为只加载了请求的项目。

The site is here: http://www.basmooarc.com 该网站在这里: http//www.basmooarc.com

Thanks 谢谢

Ric 里克

short answer 简短的回答

Add a Cache-Control: no-store HTTP header for XHR responses. 为XHR响应添加Cache-Control: no-store HTTP标头。

long answer 答案很长

I'm pretty sure this is a bug in Chrome. 我很确定这是Chrome中的一个错误。 I found the exact same bug in my app, and it works fine in Firefox but breaks in Chrome. 我在我的应用程序中发现了完全相同的错误,它在Firefox中正常工作但在Chrome中中断。 I think the issue is that Chrome caches the XHR response and serves it from the cache when you press the back button. 我认为问题在于,当您按下后退按钮时,Chrome会缓存XHR响应并从缓存中提供响应。 My app uses Etags, but Chrome does not bother to check the Etag. 我的应用使用了Etags,但Chrome并不打算查看Etag。 It just uses the cached response, which is missing all the outer content. 它只使用缓存的响应,它缺少所有外部内容。 The best solution I've come up with so far is to add no-store to the cache control header for XHR responses. 到目前为止,我提出的最佳解决方案是在XHR响应的缓存控制头中添加no-store

You can see the behavior through Chrome's net-internals page. 您可以通过Chrome的net-internals页面查看该行为。 Type chrome://net-internals in the URL bar, open the Events tab and go through the steps to reproduce your bug. 在URL栏中键入chrome://net-internals ,打开“事件”选项卡,然后完成重现错误的步骤。 When you go to a non-ajax page and then press the back button, you'll see a URL_REQUEST entry for the URL of the page you're trying to go to, but Chrome just checks the cache and that's it. 当您转到非ajax页面然后按后退按钮时,您会看到一个URL_REQUEST条目,其中包含您尝试访问的网页的网址,但Chrome只会检查缓存,就是这样。 Contrast that with a normal request for that URL. 与该URL的正常请求形成对比。 The normal one will have a cache check, followed by an HTTP_TRANSACTION_SEND_REQUEST section, which is where Chrome makes the actual HTTP request. 正常的一个将进行缓存检查,然后是HTTP_TRANSACTION_SEND_REQUEST部分,这是Chrome发出实际HTTP请求的部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM