• Resolved Rob de Cleen

    (@rdc2701)


    Hi,

    I was considering unloading unused scripts and styles on specific pages, through functions.php or a plugin like Asset CleanUp. I was also wondering however about the final impact. I cannot seem to logically get my head around the “verdict”, so I was hoping maybe you or someone else could help me out getting things clearer.

    My reasoning is this:

    1)
    Without W3TC, unloading unused scripts and styles for certain pages or post types initially seems like a good idea, as it would reduce loading time per page. So each page would only get the assets they need loaded.

    2)
    With W3TC and without the Asset Cleanup, the combined scripts and styles would be one (larger) block — so a heavier download — but it would be advantageous on access to subsequent pages, as all needed JS+CSS would already be loaded the first time and thus be client browser cached.

    3)
    With both W3TC and the Asset Cleanup however, the combined scripts and styles would be different blocks for certain pages, posts, post types. Access to subsequent pages would then each need to load their respective blocks (with generally needed duplicates!), as each page gets their own combination and thus is not browser cached after the first page visit.

    In other words, would this then result in an actual slowing down of the cache advantage? Different JS/CSS blocks would exist, resulting in extra HTTP requests and multiple downloads before all site assets are client cached for various pages.

    Do you have any real world experience with this? Thanks in advance for the help and advice.

    Rob

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @rdc2701

    Thank you for reaching out and I am happy to assist you with this.
    First of all, yes you should unload unnecessary files.
    Check which files (belonging to specific plugins or within the active theme) you believe are needed or not. If, for example, you’re on the homepage and there’s “Contact Form 7” files loading and you’re sure you’re not using any contact form on the homepage, then you can unload the 2 files (CSS & JS) that are loaded by “Contact Form 7”. Same goes for other elements such as sliders, carousels, CSS & JS belonging to Checkout pages for example and so on. There’s no way to automate this 100% as only you (the admin) know when and how you will use specific plugins that will load CSS / JS files. For example, you might have a “Contact” link on the homepage that will open a modal box (that is not seen by default when the page is loading), in this case, you will need to keep “Contact Form 7” files on the homepage.

    Often, you don’t need lots of files, so once you unload the unused JS/CSS from a page, you can use a W3TC Minify to minify and combine the remaining loaded files which will result in a lighter and faster website.

    I hope this helps!

    Thanks!

    Thread Starter Rob de Cleen

    (@rdc2701)

    Hi Marko,

    Thank you for the good explanation of the how to handle this. I already have this planned, as I mentioned. But I cannot wrap my head around the (in my mind at least) conflicting logic.

    Your answer does not include the answer to my main question about this:
    Will the resulting (thus multiple) combined JS&CSS packages for each page/post/post-type not lead to additional http requests throughout the site?

    I mean, the procedure you outline does function well for each individual page, obviously.
    BUT…and this is my main question:

    If I should leave all script and styling as is, there would be one big JS and CSS file created by W3TC which can then apply to all pages regardless, thus saving the downloading of the individual “customized-per-page-or-post” JS and CSS combinations on subsequent site pages visited.

    So, in other words, is the customzing of the JS and CSS per page/post not offset by the extra downloading of these “customised” combinations? Especially since each of these special combinations would also contain the parts which are needed on all pages regardless.

    I hope I explained myself well and you understand my question. But if there is some kind of flaw in my logic, please correct me.

    Thanks for your help
    Rob

    ADDED Explanation about my conundrum:
    Let me try to explain with a practical example.

    Scenario 1 – Restrict ContactForm7 JS and CSS to only Contact Page
    (which I already had, by the way)
    Home Page: W3TC creates combined/minified JS-combi-1 and CSS-combi-1
    Contact Page: W3TC creates combined/minified JS-combi-2 and CSS-combi-2

    Visitor goes to Home Page > browser downloads JS-combi-1 and CSS-combi-1
    Visitor goes to Contact Page > browser downloads JS-combi-2 and CSS-combi-2

    Scenario 2 – No asset cleanup done
    Home Page: W3TC creates combined/minified JS-combi-1 and CSS-combi-1
    Contact Page: no combi-2 is needed, combi-1 has it all

    Visitor goes to Home Page > browser downloads JS-combi-1 and CSS-combi-1
    Visitor goes to Contact Page > browser downloads nothing, JS-combi-1 and CSS-combi-1 are already in the browser cache.

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @rdc2701

    Thank you for the clarification.
    This kind of tradeoff exists, and the result depends on the user’s behavior on each specific website.
    In general, however, it’s better to include only what’s used on-page.
    Another alternative is to not combine assets at all and leave http2 on loading assets efficiently.
    However, in most cases, combined assets load faster even when separate ones are powered by http2.
    So there is no correct answer when it comes to this. It simply depends on a use case and the behavior of different environments (plugins, themes, etc.).
    Thanks!

    Thread Starter Rob de Cleen

    (@rdc2701)

    Hi Marko,

    Once again, thank you for the explanation, I understand the possible issues much better now as well as possible workarounds. I will have to run some live tests then to see which approach works best.

    I was just wondering beforehand what the impact would become when there are many different loading patterns on many different pages. Guess the only way to find out is to try out all scenarios. ??

    Thank you for your time and work!
    Rob

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @rdc2701

    You are most welcome!
    I am glad if I was able to assist with this.
    We would really appreciate it if you could take a minute and post a review here. This will help us to continue offering a top-notch product to users.
    Thanks!

    Thread Starter Rob de Cleen

    (@rdc2701)

    Of course, apologies, thought I had already done it years ago ??
    (W3TC has been my favorite for more than 5 years)

    Rob

    Thread Starter Rob de Cleen

    (@rdc2701)

    Hi,

    I am still trying to understand the website cache expiration behaviour when W3 Total Cache is combined with Asset CleanUp.

    I have W3TC combining and minifying JS & CSS automatically, works fine.
    I have set Asset CleanUp to just combine the remaining JS & CSS. Which also seems to be working fine in this combination.

    I have however noticed some strange things happening with the cache expiration. Originally I had W3TC set with a very long cache expiration for those files. With Asset CleanUp active however, it seems like the caching is cleared around every 8 hours? This of course results in a (temporary) slowdown of the website, as the browser needs to download the generated assets again before being able to take them from the cache.

    From what I understood so far, the expiration in W3TC and Asset CleanUp (for JS & CSS) need to be set to equal values, so I have opted to set them both to 14 days (= 1209600 seconds).

    > Asset CleanUp > Clear previously cached CSS/JS files older than 14 days
    > W3 Total Cache > Minify > Advanced:
    Update external files every: 86400 seconds (24 hours)
    Garbage collection interval: 86400 seconds (24 hours)
    > W3 Total Cache > Browser Cache > CSS & JS > Expires header lifetime: 1209600 seconds (14 days)
    > W3 Total Cache > Browser Cache > HTML & XML > Expires header lifetime: 1209600 seconds (14 days)

    My questions:
    1. will these settings really prevent the cache clearing of both plugins to NOT interfere with each other?
    2. Will clearing (purging) the cache in W3TC also clear the Asset CleanUp cache and vice versa?
    3. How can I assure both caches are kept in sync and cleared in sync?

    I have put the exact same questions to support for Asset CleanUp also.

    Once again, thank you in advance for your help,

    Rob

    • This reply was modified 3 years ago by Rob de Cleen. Reason: typo fixed
    Thread Starter Rob de Cleen

    (@rdc2701)

    Link to the support forum question in Asset CleanUp:
    https://www.ads-software.com/support/topic/questions-about-asset-cleanup-with-w3-total-cache/
    They have an 8 hour expiry set, see their docs:
    When is the cache re-built and the optimized cached files updated?
    The caching expires in 8 hours and the optimized file is re-built after this time passes OR whenever the versioning for that file (the “/?ver=” value) is updated, whichever happens first.
    (https://www.assetcleanup.com/docs/how-css-js-are-created-within-the-caching-directory/)

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @rdc2701

    Thank you for your patience.
    The W3 Total Cache cannot know when the other plugin will purge the cache.
    For example:
    wp-admin/admin-post.php?action=assetcleanup_clear_assets_cache calls OptimizeCommon::clearCache()

    It deletes the cached files and directories not used. Once the files are deleted, new files are being created which of course are changing the content of the HTML, after that, the W3TC sees that the page is updated, and given the options enabled in Performance>Page Cache>Purge Policy, the W3TC purges the cache.

    The Browser Cache TTL rules set in W3 Total Cache for JS/CSS mean that the JS/CSS files will be cached in the Browser of the visitor for 14 days in your case. Now if the content is the same and file names remain the same the TTL will expire after those 14 days and a new set of files will be cached.
    If however the file name is charged according to the article by versioning, that means that the newly versioned file will be cached.
    I hope this helps!
    Thanks!

    Thread Starter Rob de Cleen

    (@rdc2701)

    Hi Marko,

    Once again thanks for your patience with this. The wait was more my fault, I had to change the status from resolved to open because of the additional question ??

    I will test some more, but my guess is that in practice it will be too difficult for my users to remember that they have 2 caches to deal with if I use Asset CleanUp as well. So I will just find ways to do the same without AssetCleanUp in functions.php, then let W3TC handle everyhting else.

    So thanks for all the time spent and the support. Resolved.

    Rob

    Plugin Contributor Marko Vasiljevic

    (@vmarko)

    Hello @rdc2701

    Thank you for the feedback.
    You are most welcome!
    Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Advice on W3TC combined with asset cleanup’ is closed to new replies.