WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
[resolved] Remote dependencies loading after minified JS (7 posts)

  1. xnau
    Member
    Posted 2 years ago #

    I'm grabbing my jQuery and jQuery UI from Google, but they are loading after the combined minified JS. How can I get the combined JS to load after my remote dependencies? I have the dependencies set up properly in my wp_register_script calls and it all works fine with the JS minify turned off.

    Or should I just load those scripts from my own server? Just trying to spread the load around.

    Anybody else using this plugin with the Google library?

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. xnau
    Member
    Posted 2 years ago #

    OK, let me ask this question in a different way: is there any way to affect where in the HTML the combined JS is placed?

  3. xnau
    Member
    Posted 2 years ago #

    Well, I did some digging and what I've learned is that when JS Minify is in "auto" mode, it puts the combined JS at the top of the head. I was able to alter the plugin code to get it to place the code at the foot of the body tag, so now all my wp_localize_scripts() variables are set before the scripts are loaded.

    Getting my jQuery from Google still, but now it's OK, because the combined JS is now loading at the end of the document.

  4. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    You have to use manual mode to load remote files in W3TC in the current releases.

  5. Riccardo
    Member
    Posted 1 year ago #

    Hi xnau,
    good digging in the code!
    I am actually having the same problem, but I would rather not use the manual mode, so I was wondering if you could share the patch.

    Frederick, amazing job with the plugin.
    Is there any reason to put the the minified code at the top of the head? Would it be possible to make it configurable?

    thanks guys!
    Riccardo

  6. Riccardo
    Member
    Posted 1 year ago #

    Hey guys,
    in the end I found this article from the forum and the suggestions worked.
    Now the file to modify is Minify.php and not Plugin.php, but the trick pretty much did it.

    Great!

    Riccardo
    http://www.gurtip.it

  7. vinx77
    Member
    Posted 1 year ago #

    When you keep getting an error that jquery is not loaded, you need to check this bug-report or implement Riccardo's hack and also do the following steps.

    find the following code in Minify.php:
    if ($ext != '.js' && $ext != '.css') {
    return false;
    }
    And add just below or above:
    // don't add jquery in the cache
    if (strpos($file, "jquery.min.js")===true) {
    return false;
    }

    Alternatively you could choose to prevent everything that is from google-apis as these are probably cached within the browser:
    // don't add css/js hosted by googleapis
    if (strpos($file, "googleapis.com")===true) {
    return false;
    }

    Hope this helps!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic