Add config option to defer scripts

Created on 17 January 2024, 5 months ago
Updated 22 January 2024, 5 months ago

Howdy πŸ‘‹πŸΌ It's really clear from the module name and project page that config options are not really desired. I hesitated to even file an issue, but it can't hurt to ask, right?

Problem/Motivation

The module causes frontend performance issues to get flagged on industry-standard audits. Other modules have these config options already, but this module is much easier to maintain when you manage a whole fleet of sites and want to keep many sites' worth of config in version control or Ansible.

Steps to reproduce

Install and configure module for use. Since there's only one way to output the GTM code, it cannot be deferred.

Proposed resolution

Add a boolean option to defer the scripts inside gtm_barebones.settings. The option would affect how the HTML for GTM gets built:

  • False (default): current behavior
  • True: JS code gets output to files dir, and gets loaded as an external <script> with the defer attribute present. The other external GA script also gets the defer attribute.

Remaining tasks

User interface changes

Add a configuration screen to toggle the config option.

API changes

None

Data model changes

None

✨ Feature request
Status

Closed: won't fix

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany rupl

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @rupl
  • πŸ‡¦πŸ‡ΊAustralia dpi Perth, Australia

    Thanks for the issue @rupl.

    Do you think we can get away with universally adding defer?

    In keeping with the project mandate, build in configuration is something I want to avoid.

    At most, I'd want to make it alterable by a render alter hook or something.

    Is the local caching necessary to achieve this? this is a feature I'd really want to avoid. For which the main GTM project β†’ would be best.

  • πŸ‡©πŸ‡ͺGermany rupl

    Do you think we can get away with universally adding defer?

    Adding it universally would be possible and I'd personally like that, but it creates a chance that some very quick bounces aren't counted. Some folks would undoubtedly find it undesirable.

    Is the local caching necessary to achieve this? this is a feature I'd really want to avoid.

    Yes, using the <script defer> requires an external JS reference (using the src attribute). So the module would have to write JS to the files dir during cache rebuild or cron. If that's a deal-breaker then I'll go ahead and close the issue.

    Thanks for the response!

  • Status changed to Closed: won't fix 5 months ago
  • πŸ‡©πŸ‡ͺGermany rupl
Production build 0.69.0 2024