让WooCommerce加载页面上的所有变体图像加载负载
我正在使用 Woocommerce v6.3.1 和 WooCommerce v1.1.19 的变体样本 在我的 Wordpress 网站上显示所有不同的变体。
我注意到它以舒适的速度加载产品页面,但不同属性的图像会进行 ajax 调用并在访问点加载该变体的图像(即单击样本按钮),这有相当大的滞后。然后该图像被缓存,因此该变体的后续访问没有任何加载时间,但我希望在页面加载时加载该初始调用。
我知道我可以对图像进行优化,而且我也这样做了。目前图像的平均大小为 500kb。
有没有办法让所有变体的所有图像在页面加载时加载?如果这些 ajax 调用仍然是异步进行的,那就太好了!
I am using Woocommerce v6.3.1 and Variation Swatches for WooCommerce v1.1.19 to display all the different variations on my Wordpress website.
I notice it loads a product page at a comfortable speed but the images for a different attribute makes an ajax call and loads the image for that variation at the point of access(ie the swatch button is clicked), which has quite a considerable lag. The image is then cached so the subsequent access of that variation does not have any load time but it's that initial call that I would prefer be loaded on page load.
I am aware that I can make optimizations on the images and I have done so as well. The average size of an image is 500kb at the moment.
Is there any way to make all the images of all variations load on page load? It would be great if those ajax calls are still made asynchronously too!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将所有变体图像放入“ IMG”元素中。并通过设置“显示:无”使“ IMG”元素消失。这样,浏览器将在遇到元素后立即开始下载inages,并在下次需要显示时被缓存。您可以在产品循环中执行此操作:
在循环外,您可以使用此操作:
You can put all the variation images in ‘img’ elements. And make the ‘img’ element dissapear by setting ‘display:none’. That way, the browser will start downloading the inages as soon as it encounters the elements and they will be cached for the next time they need to display. You can do this in the product loop:
Outside the loop, you can use this: