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

  1. xnau
    Posted 3 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?


  2. xnau
    Posted 3 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
    Posted 3 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
    Plugin Author

    Posted 3 years ago #

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

  5. Riccardo
    Posted 3 years 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!

  6. Riccardo
    Posted 3 years 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.



  7. vinx77
    Posted 2 years 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

  • W3 Total Cache
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic