如何解决prestashop中的Defer解析JavaScript? [英] How to fix the Defer parsing of JavaScript in prestashop?

查看:376
本文介绍了如何解决prestashop中的Defer解析JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gtmetrix.com上测试了我的网站。它向我显示了以下错误:

在初始页面加载期间解析了717.8KiB的JavaScript。推迟解析JavaScript以减少页面呈现阻塞



要解决此错误,我已经从google找到以下解决方案:



1.使用async属性:

当我在脚本中使用async属性时,它在谷歌浏览器中正常工作,但在其他情况下不起作用浏览器



例如:

  {foreach $ javascript.external as $ js} 

< script async type =text / javascriptsrc ={$ js.uri}{$ js.attribute}>< / script>

{/ foreach}

2.使用defer属性:同样会造成上述问题。

3。把javascript放到最下面:



在我的网站中有3到4个滑块,当我把javascript从上到下,滑块不能正常工作,如果我删除底部的JavaScript,并将其放入标题,它工作正常。
所以请告诉我如何解决这个错误。



我正在等待您的重播

解决方案

你应该把你的javascript放在页面的底部,并且重写你的滑块,以便即使在没有加载javascript时也能很好地显示。您的滑块应该显示没有问题的第一张图片,并在javascript完全加载时顺利启动。


I have tested my website on gtmetrix.com. It shows me the following error:

717.8KiB of JavaScript is parsed during initial page load. Defer parsing JavaScript to reduce blocking of page rendering

To solve this error , I have found the following solution from google:

1.Use the async attribute :
When I use the async attribute in script .It works fine in google chrome but it does not work in other browser

ex :

{foreach  $javascript.external as $js}

<script async type="text/javascript" src="{$js.uri}" {$js.attribute} ></script>

{/foreach}

2.Use the defer attribute: same create the above issue.

3. Put javascript top to bottom :

In my website there are 3 to 4 slider when i put the javascript top to bottom , slider does not work properly if i remove the javascript at bottom and put in header it works fine. So please tell me how to solve this error.

I am waiting for your replay

解决方案

You should put your javascript at the bottom of your page and rewrite your sliders to display well even when javascript isn't loaded. Your slider should show the first picture without problems and starts smoothly when javascript is fully loaded.

这篇关于如何解决prestashop中的Defer解析JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆