Skip to content

Minify script in production builds #5

Open
@muuvmuuv

Description

@muuvmuuv

Would it be possible to minify the script in production environments? I think the script just needs to be injected in another way so gatsby can handle the script itself.

<script id="simple-analytics-loader" type="text/javascript" data-loaded="false">!(function(s, i, m, p, l, e) {
    const parent = document.querySelector('#simple-analytics-loader');
    if (!parent) return;
    const dnt = s.doNotTrack || m.doNotTrack || m.msDoNotTrack;
    if (/yes|1/.test(dnt) && parent) {
      parent.setAttribute('data-enabled', false);
      return console.warn('Simple Analytics: Not loading script when doNotTrack is enabled');
    }
    l = i.createElement(p);
    l.addEventListener('load', function() {
      if (parent) {
      parent.setAttribute('data-loaded', true);
        let event;
        if (typeof Event === 'function') {
          event = new Event('script-loaded');
        } else {
          event = document.createEvent('Event');
          event.initEvent('script-loaded', true, true);
        }
        parent.dispatchEvent(event);
      }
    }, false)
    l.async = "true";
    l.src="https://scripts.simpleanalyticscdn.com/latest.js";
    l.type="text/javascript";
    l.setAttribute('id', 'simple-analytics');
    
    e = i.getElementsByTagName(p)[0];
    e.parentNode.insertBefore(l, e);
  })(
    window,
    document,
    navigator,
    'script'
  )</script></html>

Metadata

Metadata

Assignees

No one assigned

    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