缓存网页时使用 JavaScript 而不是图像有缺点吗?
我正在网页上显示条形码,想知道在缓存方面使用 JavaScript 而不是图像或 pdf 来执行此操作是否有任何缺点?
I'm displaying a bar code on a web page and wondering if there is any disadvantage using JavaScript to do it rather than an image or pdf in terms of caching?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
缓存很可能应用于脚本和图像,因此在这种情况下应该没有太大区别。但是,我认为您的图像会时不时地发生变化,显示不同的条形码?在这种情况下,生成代码的脚本可以具有优势,因为生成代码永远不会更改并且将保持缓存,而必须再次下载不同的图像。
Caching will most likely be applied on scripts and images, so in that case there shouldn't be much difference. However, I think your image will change every now and then showing a different bar code? In that case a script that generated the code can have the advantage because the generation code never changes and will stay cached while the differing images must be downloaded again.
如果 JavaScript 位于外部文件中,则可以对其进行缓存,因此请使用它。然而,请注意,某些浏览器禁用了 Javascript,随着 NoScript 等插件的流行,用户的比例可能比您想象的要多。
图像的优点是它可以在更多的浏览器上运行(100%)。如果这是访客可能会做的事情,它也可以被保存。对于最终用户来说,保存 JS 文件的输出有点棘手。
所以我更喜欢图像,除非您要生成数百个新条形码并且有一个 JS 解决方案可以使这项工作变得更加容易。
Cliffnotes:这取决于你的情况。但希望我已经概述了最重要的优点/缺点。
Javascript can be cached if it's in an external file, so go for it. Recognise however, that some browsers have Javascript disabled, it's probably more % of users than you would think with the popularity of plugins such as NoScript.
The advantage of an image is it will work on far far more browsers (100%). It can also be saved, if this is something visitors might do. Saving the output of a JS file is a little trickier for end users.
So I would favour an image, unless you are generating hundreds of new barcodes and have a solution in JS that makes that job a lot easier.
Cliffnotes: It depends on your situation. But hopefully I've outlined the most important pros/cons.
您通过 javascript“生成”的任何代码都无法缓存
如果您使用 javascript 加载图像或其他文档,那么它将被缓存。
Any code you 'produce' via javascript cannot be cached
If you are using javascript to load an image or some other document then it will be cached.