使外部图像和 JS 文件不影响页面加载时间的最佳方法是什么?
在我使用的许多页面上,有许多外部(非关键)外部图像和 js 文件被调用,从而影响加载时间。其中之一是广告公司的跟踪像素,有时可能需要几秒钟的时间才能加载,您可以看到它挂在浏览器中,因此它的用户体验很差。有没有一种方法可以加载这些内容而不将它们算作初始页面加载?我见过类似的东西启动计时器,一旦计时器触发,它们就会加载,但我担心如果用户离开页面太快,跟踪像素将没有时间加载。
On a lot of the pages I work with there are a lot of external(non-critical) external images and js files that get called that affect the load time. One of these is a tracking pixel for an ad company that sometimes can take a few seconds to load and you can see this hanging in the browser so it gives a poor user experience. Is there a way that I can load these and not have them count as the initial page load? I've seen similar things that launch a timer and once the timer fires they load but I'm worried that if the user leaves the page too quickly the tracking pixel wont have time to load.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实并非如此——使用 gif 进行跟踪的目的是跟踪用户,无论他们是否有 javascript。延迟 gif 的加载需要 JavaScript,因此会破坏要点并可能弄乱你的统计数据。
最好的方法是将这些“页面加载不必要的”内容放在代码末尾的结束正文标记内。
Not really - the point of tracking using a gif is to track users regardless of whether they have javascript or not. Delaying the load of the gif would require javascript, so would defeat the point and potentially mess up your stats.
The best method is to put these 'unnecessary for page load' things at the end of the code, inside the closing body tag.
如果您可以在网页上进一步加载跟踪像素,最好尽可能靠近结束 BODY 标记,它可能会首先处理该图像之前的所有其他内容,从而使页面加载在图像发生时显得更快加载速度不是很快。
这可以通过 Yahoo YSlow 的“超速最佳实践来解释(如果稍微断章取义)上您的网站”部分将脚本放在底部。
If you can load the tracking pixel further down on the webpage, preferably as close to the end BODY tag as possible, it will likely process all other content prior to that image first, making the page load appear to occur faster in the event the image isn't loading very fast.
This can be explained (if taken slightly out of context) by Yahoo YSlow's "Best Practices for Speeding up your Website" section on put scripts at the bottom.