Skip to content

Remove comments / bundle JS? #23

Open

Description

@stuartcusackie

I'm seeing a lot of comments in the scripts in my website's source code:

// Runs synchronously before any Google tag loads. It has to be inline and it has to read the
// cookie in JS rather than PHP, otherwise a statically cached page bakes in one visitor's consent.
 // Consent defaults can only be set once, so a second copy on the page must not push again

// Runs synchronously before any Google tag loads. It has to be inline and it has to read the
// cookie in JS rather than PHP, otherwise a statically cached page bakes in one visitor's consent.

// There's some string sub done here before being loaded. It's meant to be odd
// Consent itself is handled in alt-cookies-consent-default.js, which runs before any tag
// loads rather than waiting for this event. All that's left to do here is show the toast
// to anyone who hasn't chosen yet.

I understand they are useful for development. Perhaps all the scripts can be bundled and minimised with Vite, which would automatically remove all comments?

Or if you have another solution?

Thanks!

Activity

  1. Alt-Charlie commented on Jul 29, 2026

    @Alt-Charlie
    Contributor

    Hi @stuartcusackie, I assume this is in the pre-release candidate version? If so, we will strip these out ahead of the final release.

  2. stuartcusackie commented on Jul 29, 2026

    @stuartcusackie
    Author

    It's also occuring on v1.2.7. This is the source code of a production website:

    <script> // There's some string sub done here before being loaded. It's meant to be odd
    --
    document.addEventListener("DOMContentLoaded", (event) => {
    window.altCookies.toast = document.getElementById('alt-cookies-consent-toast');
    window.altCookies.toastOverlay = document.getElementById('alt-cookies-consent-toast-overlay');
    window.altCookies.cookieLifetime = 30;
    window.altCookies.denyGtagTracking();
    let cookie = window.altCookies.getAltCookie();
    // Show the toast if they're new / expired
    if ( cookie === null) {
    window.altCookies.toast.classList.remove('alt-cookies-translate-y-full')
    window.altCookies.toastOverlay.classList.remove('alt-cookies-hidden')
    return;
    }
     
    if(typeof gtag === 'undefined') {
    return;
    }
     
    switch(cookie) {
    // Necessary and Analytics
    case "2":
    gtag('consent', 'update', {
    'ad_storage': 'denied',
    'ad_user_data': 'denied',
    'ad_personalization': 'denied',
    'analytics_storage': 'granted'
    });
    console.log('Analytics consent')
    break;
    // Necessary and Advertising
    case "3":
    gtag('consent', 'update', {
    'ad_storage': 'granted',
    'ad_user_data': 'granted',
    'ad_personalization': 'granted',
    'analytics_storage': 'denied'
    });
     
    console.log('Advertising Consent')
    break;
    // Necessary, Analytics and Advertising
    case "4":
    gtag('consent', 'update', {
    'ad_storage': 'granted',
    'ad_user_data': 'granted',
    'ad_personalization': 'granted',
    'analytics_storage': 'granted'
    });
     
    console.log('All Consent')
    break;
    // Accounts for necessary which doesn't need anything
    default:
    gtag('consent', 'update', {
    'ad_storage': 'denied',
    'ad_user_data': 'denied',
    'ad_personalization': 'denied',
    'analytics_storage': 'denied'
    });
     
    console.log('All Consent Denied')
     
    break;
    }
    });
    </script>
    
    
  3. self-assigned this
    on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions