使用 HTML5 预取的危险?

发布于 2024-12-16 14:38:37 字数 393 浏览 3 评论 0原文

好的,所以这还不是一个大问题,因为它仅受少数浏览器支持:

  • Mozilla Firefox:支持
  • Google Chrome:自版本 13 起支持(使用替代语法)
  • Safari:当前不支持 Internet
  • Explorer:当前不支持

但是,预取让我抽搐。如果用户登陆您的页面并跳转到另一个网站,您是否为他们访问您的预取链接的带宽付费?

开发人员预取页面上的每个链接是否存在风险,这反过来又会使网站的用户体验变慢?

看起来它可以改变分析。人们会通过预取强制用户浏览页面吗?

安全性,您不会知道正在预取哪些页面。它可以预取恶意文件吗?

对于使用量有限的移动用户来说,所有这些预取是否会很痛苦?

Ok, so it isn't a huge worry yet as it is only supported by a few browsers:

  • Mozilla Firefox: Supported
  • Google Chrome: Supported since version 13 (Use an alternate syntax)
  • Safari: Currently not supported Internet
  • Explorer: Currently not supported

However, prefetch makes me twitch. If the user lands on your page and bounces off to another site have you paid for the bandwidth of them visiting your prefetch links?

Isn't there a risk of developers prefetching every link on the page which in turn would make the website a slower experience for user?

It looks like it can alter analytics. Will people be forcing page views onto users via prefetch?

Security, you wont know what pages are being prefetched. Can it prefetch malicious files?

Will all this prefetching be painful for mobile users with limited usage?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天荒地未老 2024-12-23 14:38:37

我不能称自己是该主题的专家,但我可以做出以下观察:

  1. 只有在已知有益的情况下才应考虑预取。对所有内容都启用预取是愚蠢的。这本质上是服务器负载与用户体验的平衡。
  2. 我还没有研究过 HTML5 预取规范,但我想他们已经指定了一个标头,其中指出“此请求正在作为预取的一部分执行” ”,这可用于解决分析问题 - 即“如果这是预取,请勿将其包含在分析统计信息中”。
  3. 从安全角度来看,人们会期望预取遵循相同的交叉-域规则为阿贾克斯做到了。这将缓解 XSS 问题的任何情况。
  4. 支持 HTML5 预取的移动浏览器应该足够智能,能够在使用 WiFi 时打开它,并在使用可能昂贵或缓慢的网络连接形式(例如 2G)时关闭它。 /3G。

正如我所说,我不能保证上述任何事情,但是(与任何技术一样)这是最佳实践的案例。您不会使用Cache-Control 强制将网站上的每个页面缓存一年。您也不希望浏览器满足跨域 Ajax 请求。希望预取也能采取同样的考虑。

I can't call myself an expert on the subject, but I can make these observations:

  1. Prefetch should be considered only where it is known to be beneficial. Enabling prefetch on everything would just be silly. It's essentially a balance of server load vs user experience.
  2. I haven't looked into the HTML5 prefetching spec, but I would imagine they've specified a header that states "this request is being performed as part of prefetching", which could be used to fix the analytics problem - i.e. "if this is a prefetch, don't include it in analytics stats".
  3. From a security standpoint, one would expect prefetch to follow the same cross-domain rules as Ajax does. This would mitigate any cases where XSS is an issue.
  4. Mobile browsers that support HTML5 prefetch should be smart enough to turn it on when using WiFi, and off when using potentially expensive or slow forms of network connection, e.g. 2G/3G.

As I've stated, I can't guarantee any of the above things, but (like with any technology) it's a case of best practices. You wouldn't use Cache-Control to force every page on your site to be cached for a year. Nor would you expect a browser to satisfy a cross-domain Ajax request. Hopefully the same considerations were/will be taken for prefetching.

相权↑美人 2024-12-23 14:38:37

为了回答分析和统计的问题,规范有以下内容:

为了确保兼容性并提高预渲染请求的成功率,目标页面可以使用[PAGE-VISIBILITY]来确定页面渲染时的可见性状态,并实现适当的逻辑以避免可能导致预渲染的操作被放弃(例如非幂等请求),或因触发而产生不需要的副作用(例如在显示页面之前触发分析信标)。

To answer the question of analytics and statistics, the spec has the following to say:

To ensure compatibility and improve the success rate of prerendering requests the target page can use the [PAGE-VISIBILITY] to determine the visibility state of the page as it is being rendered and implement appropriate logic to avoid actions that may cause the prerender to be abandoned (e.g. non-idempotent requests), or unwanted side-effects from being triggered (e.g. analytics beacons firing prior to the page being displayed).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文