• Resolved Remco Tolsma

    (@remcotolsma)


    On a website we are currently getting the following error:

    Uncaught SyntaxError: Cannot use import statement outside a module (at siteground-optimizer-combined-js-4c066a5266b58bf7cc9930ae49d96fe4.js:122:508)

    This is because a plugin enqueues a module script and changes the script tag via the script_loader_tag filter to <script type="module" src="..."></script>.

    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type

    We were wondering if it might be wise for the SiteGround Optimizer to exclude scripts with type="module" from combining JavaScript by default?

    Or are there situations where <script type="module" src="..."></script> can be successfully combined? (I’m not a JavaScript expert).

    • This topic was modified 2 years, 9 months ago by Remco Tolsma.
    • This topic was modified 2 years, 9 months ago by Remco Tolsma.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Georgi Ganchev

    (@georgiganchev)

    Hello @remcotolsma,

    We have informed our developers about the issue and they will take the time to investigate this and consider if we can modify the plugin to exclude such scripts.

    If we require further details from your end we will update this thread.

    Best regards,
    Georgi Ganchev

    Plugin Author Elena Chavdarova

    (@elenachavdarova)

    Hi @remcotolsma,

    We have included a filter to the plugin which you can use to exclude all inline scripts of type module from combination.

    The filter you can use is:

    add_filter( 'sgo_javascript_combine_exclude_all_inline_modules', '__return_true' );

    Additionally there is a filter which will exclude all inline scripts no matter of their type as well:

    add_filter( 'sgo_javascript_combine_exclude_all_inline', '__return_true' );

    I hope this will be of help!

    Best Regards,
    Elena

    Thread Starter Remco Tolsma

    (@remcotolsma)

    Thanks, but without answers to our questions I don’t know if a filter is the best solution.

    We were wondering if it might be wise for the SiteGround Optimizer to exclude scripts with type="module" from combining JavaScript by default?

    Or are there situations where <script type="module" src="..."></script> can be successfully combined? (I’m not a JavaScript expert).

    if <script type="module" src="..."></script> scripts should not be combined at all then you shouldn’t introduce a filter, but exclude it by default.

    Plugin Author Hristo Pandjarov

    (@hristo-sg)

    SiteGround Representative

    At this point we will not be excluding such scripts by default since that brings more risk of introducing bugs to users than using the filter when actually using it. Furthermore, each check increases the time necessary to process the request.

    Thread Starter Remco Tolsma

    (@remcotolsma)

    Hmm, without the answers to my questions I don’t know if that’s true. After all combining <script type="module" src="..."></script> by default caused an issue, that’s why this topic exists.

    Plugin Author Hristo Pandjarov

    (@hristo-sg)

    SiteGround Representative

    Yes, enabling combination does that. Exceptions are handled by default rules, interface, filter or both. This current case will be covered by a filter. I am sorry if that’s not your preferred way to handle this.

    Thread Starter Remco Tolsma

    (@remcotolsma)

    Haha, it’s not about my preferred way to handle this. I think it should be about how you can best deal the combining <script type="module" src="..."></script> elements / scripts by default. That remains a bit in the middle, but maybe it can’t get any better.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Don’t combine JavaScript type=module by default?’ is closed to new replies.