APIs & Integrations

nutanhaspe
Teilnehmer/-in

Is it possible to add javascript with defer attribute in hubspot template

Is it possible to add javascript with defer attribute in hubspot template

0 Upvotes
1 Antwort
WendyGoh
HubSpot Employee
HubSpot Employee

Is it possible to add javascript with defer attribute in hubspot template

Hi @nutanhaspe,

 

I hope all is well with you 😄

 

By defer attribute do you mean something like this:

<script defer="defer">
	//do stuff, but defer it  (runs last)
</script>

If so, I have tested it out and it works! This is the sample code that I ran:

<!doctype html>
<html lang="{{ html_lang }}" {{ html_lang_dir }}>
    <head>
        <meta charset="utf-8">
        <meta name="description" content="{{ page_meta.meta_description }}">
        <title>{{ page_meta.html_title }}</title>
        {% if site_settings.favicon_src %}<link rel="shortcut icon" href="{{ site_settings.favicon_src }}" />{% endif %}
        {{ standard_header_includes }}

    </head>

    <body>

        {{ standard_footer_includes }}
                    <script defer="defer">
      alert("helloworld");
      
      </script>
    </body>
</html>

I created a page based off this template and was able to see the alert pop up.

0 Upvotes