• Resolved Anonymous User 14978628

    (@anonymized-14978628)


    Hey Frank,

    I’ve been getting a few 404 errors recently for AO css and js files. These are AO files in the wp-content cache directory.

    Not sure why this is happening or what to do about it?

Viewing 15 replies - 1 through 15 (of 35 total)
  • Plugin Author Optimizing Matters

    (@optimizingmatters)

    Not sure why this is happening

    generally it happens when you clear AO’s cache but there are pages cached elsewhere (page cache plugin, page cache at hoster, page cache at sucuri or cloudflare or …, page cache in browser) which has pages that still refer to the old cached files.

    what to do about it?

    avoid clearing AO’s cache too often and if you do make sure to also clear any page cache you have access to.

    hope this helps,
    frank

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Those were my first thoughts/actions. I was using the plugin “Redirection” to monitor for 404s which alerted me to this, and has also allowed me to test it by spidering my site and seeing if the 404s reappear in Redirection.

    Clearing my page cache/AO cache didn’t seem to fix the issue.

    I just tried removing a preload and prefetch which i had in the header for an AO css and the issue seems to have been resolved. Strangely, the css i was preloading wasn’t the one that was being flagged as causing the 404.

    I will mark this as resolved for now and update if i notice any more AO 404s being caused by Googlebot.

    Thanks

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    AO 404s being caused by Googlebot.

    aahhhh, Googlebot errors! so this is different; based on previous similar reports and investigations it seems like Google is making requests for CSS/ JS from pages in its own extensive cache. as you can’t purge Google’s cache, there’s nothing much you can do (except not purging AO’s cache). a workaround some people implemented is a change in .htaccess to ensure that requests for non-existant autoptimized files are answered with a HTTP 410 response header (“gone”) instead.

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Oh, that would explain it then. Do you have the .htaccess code to return the 410 header?

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Figured it out. I didn’t realize you were referring to a generic htaccess code. I thought it was something specific to AO.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    great job @martychc23, have a nice weekend! ??

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Thanks Frank, sorry to have bothered you with this! Have a nice weekend also ??

    Hi, @martychc23 I also have the same Googlebot problem, you solved the error by editing your wp-content / cache / autoptimize / .htaccess or creating another .htaccess file for the redirect, could you tell me which code you implemented or an information link, please …

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Hi, I found a really good solution to this. Basically, when Googlebot encounters a file that isn’t there anymore it receives a 404 response. I found out this doesn’t actually mean the file is gone for certain, and so Googlebot will continue trying for that file over time.

    The best way to deal with files/pages you remove is to return a 410 response, which means that it’s gone for good and so stop trying to access it.

    There’s an easy way to deal with this by adding the following to your 404.php file:

    header($_SERVER["SERVER_PROTOCOL"] . " 410 Gone");

    If you don’t have a 404.php you can create one by making a .php file containing the following:

    <!DOCTYPE html>
    <?php  
    header($_SERVER["SERVER_PROTOCOL"] . " 410 Gone");
    header("Cache-Control: max-age=2592000");
    ?>
    <div id="main-content">
    <div class="container">
    <div id="content-area" class="clearfix">     
    <h1><?php esc_html_e('Page Not Found'); ?></h1>
    </div>
    </div>
    </div>

    That creates a very basic 404 page that returns a 410 response. I kept it basic so it doesn’t use much server resources to load.

    You can then test this by accessing a url that doesn’t exist on your site, and then looking at the network tab with Chrome developer tools. You will see the 410 response.

    Got this info from here (see last response)

    https://stackoverflow.com/questions/41997261/wordpress-change-all-404-to-410-error-code

    Hope this helps you and anyone else with Autoptimize causing 404 errors!

    Thank you, for answering and explaining the solution, greetings.

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    nice solution @martychc23, if your theme already has a 404.php you could add this code in there, executing conditionally if this is for an autoptimize_*.css or .js file (keeping normal 404 in place for other requests). good job! ??

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    Hey Frank, Just so I can avoid such issues in future. Could you please clarify when I should clear the Autoptimize cache? For example, i’ve added some css to my style.css. Should i now clear the cache? Thanks

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    For example, i’ve added some css to my style.css. Should i now clear the cache?

    No, AO will “see” the new CSS and create a new AO’ed CSS-file automatically. I clear my cache a couple of times per year.

    Thread Starter Anonymous User 14978628

    (@anonymized-14978628)

    I clear my cache a couple of times per year.

    Under what circumstances would you clear your cache?

    Plugin Author Optimizing Matters

    (@optimizingmatters)

    when I’m changing AO options, for testing purposes mainly ??

Viewing 15 replies - 1 through 15 (of 35 total)
  • The topic ‘404 Errors’ is closed to new replies.