WordPress.org

Forums

[Plugin: W3 Total Cache] Manual CSS/JS Placement (6 posts)

  1. Driklyn
    Member
    Posted 3 years ago #

    Can you tell W3 Total Cache where to place CSS/JS files by manually specifying a tag of some sort in the applicable PHP file? For instance, with W3 Minify you simply write <!-- WP-Minify CSS --> and <!-- WP-Minifiy JS -->. This is a must have!

    Currently, it is automatically placing them right after the <head> tag which breaks everything because my hosted CSS/JS files rely on external CSS/JS files, meaning my hosted files must be loaded after the external files, not before.

  2. wpreader
    Member
    Posted 3 years ago #

    I'm in a similar situation and i'm looking for a solution as described above.

  3. Driklyn
    Member
    Posted 3 years ago #

    Hi,

    I solved this by manually editing the source of the W3 Total Cache plugin. I now have my CSS files being placed directly before the </head> tag and my JS files being placed directly before the </body> tag.

    Been meaning to write a blog post about it and your reply inspired me to finally do so today. Here it is: W3 Total Cache: Better CSS/JS placement.

  4. wpreader
    Member
    Posted 3 years ago #

    I'm still in search of something like this :

    http://www.wpoptimus.com/131/html-tags-minified-js-css-wp-minify/

    But i did find in the FAQs the following:

    You'll need to manually update your theme to include your CSS and JS minify groups. The calls you'll want to make for the various cases are:

    <?php if (function_exists('w3tc_styles')): w3tc_styles('include'); endif; ?>
    Inserts the <head> CSS group at the location you choose. Multiple occurrences are allowed.
    <?php if (function_exists('w3tc_scripts')): w3tc_scripts('include'); endif; ?>
    Inserts the <head> blocking JS group at the location you choose.
    <?php if (function_exists('w3tc_scripts')): w3tc_scripts('include-nb'); endif; ?>
    Inserts the <head> non-blocking JS groups at the location you choose.
    <?php if (function_exists('w3tc_scripts')): w3tc_scripts('include-body'); endif; ?>
    Inserts the <body> blocking JS group at the location you choose.
    <?php if (function_exists('w3tc_scripts')): w3tc_scripts('include-body-nb'); endif; ?>
    Inserts the <body> non-blocking JS groups at the location you choose.
    <?php if (function_exists('w3tc_scripts')): w3tc_scripts('include-footer'); endif; ?>
    Inserts the footer JS group at the location you choose.
    <?php if (function_exists('w3tc_scripts')): w3tc_scripts('include-footer-nb'); endif; ?>
    Inserts the footer non-blocking JS group at the location you choose.

    However, i could not get it to work - . maybe because i'm always calling wp_head(). I should try it without calling wp_head().

    I'm hesitant to use your method as the changes would be over written when i update W3TC.

    Nice site by the way :)

  5. Driklyn
    Member
    Posted 3 years ago #

    Interesting, I did not know those functions existed. If you can get those to work, then I'd definitely do it that way. Let me know if you do! :)

    Honestly, I never thought about the changes being overwritten when updating. I wonder if WordPress only updates files that have newer modified dates than the current files or if they do a full overwrite of all files. If they do the former, as long as the "w3-total-cache/lib/W3/Plugin/Minify.php" file wasn't changed by W3 EDGE, you'd be safe. Of course, if it does get overwritten, it shouldn't be too hard to redo the changes. Just be sure to save a link to my blog post somewhere in case this ever does happen.

    If you do manage to get those functions working, however, that'd be the best way.

  6. Frederick Townes
    Member
    Posted 3 years ago #

    You can use a child theme to avoid having your changes lost when upgrading.

Topic Closed

This topic has been closed to new replies.

About this Topic