Home › Forums › JavaScript › Load asynchronously external file so in javascript
- This topic is empty.
-
AuthorPosts
-
March 4, 2017 at 7:30 am #252332analisParticipant
I have a problem I have an external script that slows me down the page loads, it is a lot of code so I can not add it directly in the page, I tried to add the ASYNC attribute, but the script does not work, the alternative is to upload it to delay of a few second but I do not know how to do.
Can someone help me thank you very much, following the code:
March 4, 2017 at 8:05 am #252334ShikkedielParticipantEdited – give this a go perhaps…
March 4, 2017 at 8:56 am #252336ShikkedielParticipantThis version might be better when the script has been cached:
(function() { var script = document.getElementsByTagName('script')[0]; if ('cookieChoices' in window) showMessage(); else script.addEventListener('load', showMessage); function showMessage() { cookieChoices.showCookieConsentDialog('Your message for visitors here.', 'close message', 'learn more', 'http://example.com'); } })();
Loading async’s rather tricky…
March 4, 2017 at 11:27 am #252349analisParticipantIt works, now my score in google PageSpeed Insights increased by 10 points.
thank you so much
March 5, 2017 at 3:49 am #252396analisParticipantI did controls, there is a problem function well with chrome, mozilla and safari, but it does not work for Internet Explorer and Microsoft’s edge.
March 5, 2017 at 5:39 am #252398ShikkedielParticipantPlease define “does not work” and provide a functional demo because it’s showing like this:
Although I suppose it might not be relevant anymore as PageSpeed isn’t objecting to the script when it’s at the bottom of the page.
March 5, 2017 at 9:04 am #252401analisParticipantBefore you edit the bar appeared on all browsers, now with microsoft internet explorer 11 EDGE and the bar does not appear.
The initial script was at the bottom of the page and with your edit me now 10 points higher. Something must have changed in Google Page Speed because last year I do not signaled as an error.
March 5, 2017 at 9:33 am #252402ShikkedielParticipantWhen I checked, Google did not subtract points for it…
Is there any error in the console? Again, without a demo there’s no debugging.
March 5, 2017 at 10:29 am #252403analisParticipantMY SCRIPT (78 points)
google analytics
script
</body>or
script
google analytics
</body>YOUR SCRIPT
(83 points)
google analytics
script
</body>(89 points, don’ t work in IE and EDGE)
script
google analytics
</body> -
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.