Close

Async or Defer Plugin Scripts

Jhopper
9 years ago
#9759 Quote
Avatar
  • 23
Hello,

I'm working on getting my mobile page speed down and a few of the plugins I use are blocking the page from loading.

Is there a way add an async attribute to the script tag or to have them called before the closing body tag instead of calling them in head?

Thank you :)
hristian.dimov
9 years ago
#9769 Quote
Avatar
  • Moderator
  • 386
Jhopper wrote:
Hello,

I'm working on getting my mobile page speed down and a few of the plugins I use are blocking the page from loading.

Is there a way add an async attribute to the script tag or to have them called before the closing body tag instead of calling them in head?

Thank you :)


Hi Jhopper,

All of the public views are open for modifications, so you can change where the scripts will be rendered.

For example, if you have this code:

Html.AddScriptParts("~/Plugins/SevenSpikes.Core/Scripts/SevenSpikesExtensions.js");

you can make it like this:

Html.AddScriptParts(ResourceLocation.Foot, "~/Plugins/SevenSpikes.Core/Scripts/SevenSpikesExtensions.js");


This way the javascript file will be called before the closing body tag. But to be honest I'm not sure that everything will work as expected if you change this.

Hope this helps!
Regards,
Hristian Dimov
Nop-Templates.com
Jhopper
9 years ago
#9774 Quote
Avatar
  • 23
Thank you for the reply.

I'll have a play around and see what if I can solve my issues :)

Thanks again!