CMS Development

marth
Contributor

Adding async/defer attribute on module scripts

SOLVE

Is it possible to add async/defer tag on scripts being added by a module? I checked the module documentation and it seems there's no option for it. I tried using js_render_options but it doesn't seem to work.

 

Here's my module meta.json code:

 

{
  "global" : false,
  "icon" : "fontawesome-5.14.0:Images:SOLID",
  "host_template_types" : [ "PAGE" ],
  "module_id" : 54869248124,
  "css_assets" : [ {
    "path" : "../../css/glide.core.min.css",
    "name" : "glide.core.min.css"
  }, {
    "path" : "../../css/glide.theme.min.css",
    "name" : "glide.theme.min.css"
  } ],
  "js_assets" : [ {
    "path" : "../../js/glide.min.js",
    "name" : "glide.min.js"
  }, {
    "path" : "../../js/fslightbox.js",
    "name" : "fslightbox.js"
  } ],
  "js_render_options" : {
    "position": "footer",
    "async": true
  },
  "label" : "Gallery",
  "is_available_for_new_content" : true
}

 

 

0 Upvotes
1 Accepted solution
JMoats
Solution
Contributor | Platinum Partner
Contributor | Platinum Partner

Adding async/defer attribute on module scripts

SOLVE

Yes, this is possible! Here's how your require_js function call should look:

 

{{ require_js(get_asset_url("https://example.com/cdn/"), { position: "footer", defer: true }) }}

View solution in original post

2 Replies 2
JMoats
Solution
Contributor | Platinum Partner
Contributor | Platinum Partner

Adding async/defer attribute on module scripts

SOLVE

Yes, this is possible! Here's how your require_js function call should look:

 

{{ require_js(get_asset_url("https://example.com/cdn/"), { position: "footer", defer: true }) }}
dennisedson
HubSpot Product Team
HubSpot Product Team

Adding async/defer attribute on module scripts

SOLVE

@marth 

I don't think so, but I am not 100% sure

@miljkovicmisa , do you know?

0 Upvotes