Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • bricejuszcz

    (@bricejuszcz)

    Hi,
    I ended up on the same type of error, here is how you can reproduce it by using wp_enqueue_script_module instead of wp_enqueue_script to enqueue a script.

    W3 Total Cache: 2.7.5.
    WP: 6.6.1.

    If you need to use a js file that contains an import declaration like the example below, you’ll have to use this new wp_enqueue_script_module function to enqueue the js file.

    import { data } from '/wp-content/themes/my-theme/js/data.js';

    fetch(data.url)
    .then(response => response.json()) // Parse the JSON response
    .then(data => {
    ......

    This will result in WordPress loading the js file with the type = “module” :

    <script type="module" src="https://www.mysite.com/wp-content/themes/my-theme/js/data.js" id="my-data-script"></script>

    And if W3 Total Cache is set to minify this file, it will load it without the type=”module”, and therefore trigger this js error and break the site :

    SyntaxError: Cannot use import statement outside a module

    A workaround is to stop W3TC to minify this file by filtering it out in the settings via Minify>Advanced>Never minify the following JS files:

    But it’d be better if W3TC could load the minified file with type=”module”

    Thread Starter bricejuszcz

    (@bricejuszcz)

    By the way, as we are pro customers, I used the form present in the WordPress admin, to try to get some help with this issue. After submitting the ticket I go redirected to the boldGrid/w3tc website, without any message informing me if my ticket got created or not. I didn’t receive any email regarding this ticket creation either.

    Thread Starter bricejuszcz

    (@bricejuszcz)

    Hi, Thank you for your answer.
    But why does it have to be working like this?
    We have often the case, after purging all caches, that the page is referring to a js file, like this:
    src="https://www.oursite.com/wp-content/cache/minify/20230309766c1e.js?x17256"
    But this file doesn’t exist in the /minify files. It seems Total Cache maybe started to generate this file, but didn’t succeed ?
    and when we access this file’s url, we get a 200 answering with an empty document.

    Sometimes, visiting that js file url with a different (and random) query param triggers the re-generation of the file, which is then filled with the correct js. But that’s not always the case.
    Re-purging all the cache also sometimes solves the issue… And that really makes me think that sometimes, the minification process actually fails, didn’t produce the minified file, but that Total Cache thinks the file is there.

    These are our minify settings btw:
    Minify Cache Method: Disk
    JS minifier: JSMin (default)





    Thread Starter bricejuszcz

    (@bricejuszcz)

    Thank you for your reply !
    No, I did not create another empty js file.

    I see this setting in Total Cache, in Page Cache settings :
    Cache 404 (not found) pages
    Reduce server load by caching 404 pages. If the disk enhanced method of disk caching is used, 404 pages will be returned with a 200 response code. Use at your own risk.

    It is unchecked. But it looks like we’re having this behavior on the /minify folder.

    Thread Starter bricejuszcz

    (@bricejuszcz)

    Little but important update: disabling the Total Cache plugin stops this behavior, and the not existing file does answer with 404.

    • This reply was modified 1 year, 7 months ago by bricejuszcz.
    Thread Starter bricejuszcz

    (@bricejuszcz)

    Thank you for the quick and amazing support, it works perfectly now! ??

    Thanks again !

Viewing 6 replies - 1 through 6 (of 6 total)