问题
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