How to fix the Defer parsing of JavaScript in prestashop?

核能气质少年 提交于 2019-12-12 03:53:44

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/44213288/how-to-fix-the-defer-parsing-of-javascript-in-prestashop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!