Support » Plugin: EWWW Image Optimizer » Looking to Optimize Cached Images on the Fly

  • I develop a premium theme Stallion Responsive which has built in Gravatar caching for performance reasons. When Gravatars aren’t cached Google Page Speed Insights downgrades the page loading the Gravatars because sets it’s cache time frame to only 10 mins (should be at least 7 days).

    So to improve page speed Gravatars are cached within the themes folder as jpg’s under.

    or if a child theme installed

    The site linked to above has the Gravatar caching turned on and your plugin installed, it’s also got hundreds of comments, so plenty of cached Gravatars.

    The theme can be downloaded for free (download link on the site above) and run in demo mode which includes the caching option if you need to test it.

    Running your plugin on the cached Gravatars (via the bulk optimize scan option) give some nice savings sometimes over 50% (so my theme caching code isn’t doing a great job compressing the Gravatars apparently :-(), so I’d like to optimize the images ideally as the Gravatars are cached, though that might be asking a lot.

    Doing it manually takes too long, the child theme includes a lot of header and thumbnail images (about 1,000 theme images), so it will have to scan over 1,000 images every time. I’ve already run the images built into the theme and the free child theme with your plugin before creating the zip files, so the theme zip file includes the images optimized by your plugin, so it’s overkill running them all again every time I want the Gravatar cache optimized.

    The Gravatars are cached when a visitor accesses a page with an uncached Gravatar and the cache expires on a regular basis: by default it’s set to 168 hours (7 days), but this can be changed.

    Can be quite a lot of images, I use the domain mapping plugin for some sites (means one WordPress install can run dozens of domains) and one setup that has just 6 sites running on it there are almost 500 cached Gravatar images and those aren’t even highly commented sites. I have some sites with 30,000+ comments, so going to be a lot of images that could be optimized. Just checked my most commented site and there’s over 11,000 cached Gravatars in the folder (50MBs of images).

    Any ideas on optimizing the cached images without having to use the manual option?

    While I’m asking 🙂 The theme also uses Timthumb.php, I’m finding the cached Timthumb images are sometimes shown as not being fully optimized when checking Google PageSpeed Insights tool. I don’t know why some are and others aren’t listed by the tool. The cached images don’t have a jpg, gif etc… file name, they have file format txt so your plugin I assume wouldn’t by default optimize them anyway.

    You can see at

    Under Optimize image:

    Losslessly compressing…s/adsense-click-fraud.png&w=50&h=50&q=75 could save 824B (24% reduction).

    which is this Timthumb cached image:

    Have you any experience improving Timthumb image optimization?

    Interestingly I haven’t run the bulk scan option on the site above and yet none of the cached Gravatars (which aren’t optimized) are listed as an issue. I picked that tutorial page because it has a full page of threaded comments (must be over 30 comments) so plenty of unoptimized cached Gravatar images loaded. I guess your plugin optimizes images to greater degree than Page Speed Insights looks for, so even though they aren’t optimized at the level your plugin works to, they aren’t bad enough to be considered an issue by Google.

    Great plugin, within my theme on the Performance options page I recommend my users install your plugin.



Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author nosilver4u


    I’ll respond more fully in the morning, but I just wanted to mention that you probably should reconsider using timthumb.php. I know there have been security issues with it in the past, and I believe wordpress ripped it out and replaced it with something else, or forked it or something like that. I don’t know a lot of specifics, just raised a red flag in my mind when you mentioned that script.

    Thanks for the heads up on Timthumb, not an issue though. I added Timthumb to my themes for the first time just after the Timthumb security issue, so never used the vulnerable version.

    The current version is safe and just to be on the cautious side I disabled the feature that was vulnerable in the old version. The vulnerability was related to allowing the caching of images from other domains, in Stallion Responsive it’s turned off so the only images that can be cached are local images.

    If a cached local image results in a hacked site there must have been malicious code within the local image: your site was already compromised. Add to this the current Timthumb script names the images lie this “randomstuff.txt” with code within the file that prevents it from being run as a PHP file even a local image with malicious code couldn’t be used to hack a site since the file can’t be executed.

    All that being said 🙂 I’d rather use native WordPress functions for generating the smaller images (would make optimizing so much easier), but so far not found a solution I like. Easy to find a solution that works for me, but what will work for everyone is much harder.

    Did figure out why some Timthumb cached images are not fully optimized according to Page Speed Insights, it’s Timthumbs png optimization at ‘fault’.

    There’s built in support for the popular png optimizing scripts (same ones your plugin uses) and like with your plugin you have to turn the feature on. In Timthumb it’s off by default, easy to turn it on for all theme users, BUT it assumes those PNG optimization scripts exist on the server under a specific directory.

    For my sites that will work, but for your average WordPress users I’ll run into the same issue you have with your plugin, you’ve had to include the scripts within the plugin folder. Does give me a good reason to find another way to generate cached images using native WordPress functions.


    Plugin Author nosilver4u


    Ok, lots of stuff to digest here. I’ll try not to miss anything…

    One of the first concerns you raise is that optimizing the gravatars manually takes too long, since it also has to optimize the theme (and child theme) images as well. This is only half true. EWWW IO is designed to only re-optimize theme images (actually ANY images) if they change. So this would be the ideal setup for the way you currently generate the cached images:
    1. enter the path to the theme in the Folders to optimize (which it sounds like you’ve already done).
    2. run the scan & optimize on the Bulk Optimize page
    3. Turn on schedule optimization.

    What will happen is that the first time you run it (manually or scheduled), it will attempt to optimize everything in that folder. After that, it will have a record of every image that has been processed, along with the optimized size, stored in the database. When it runs the next time, it will be able to quickly check those images (although the 11,000 images on your most active site could actually take a couple minutes to scan), and then it will only optimize the new images.

    And since you’ve already optimized the theme images, when a user updates the theme, the images won’t have changed sizes (usually), and so it will still skip those 1000 theme images.

    All that said, there is a potential here to make things happen automatically when those images are cached. There are a couple options. First, you could just run the optimizer function directly, but that isn’t very future-proof. I could (and do) change the parameters to accomodate for new enhancements, so that could break things at any time.

    The better solution is to use something that uses the built-in WP_image_editor class (or use it directly yourself). I thought there was an official WP fork of timthumb, but I must have confused it with something else, because I can only find this: It uses the wp_image_editor class, so anything that is generated by it will be auto-optimized. Not sure if that will work for you, but it seems like a decent solution.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Looking to Optimize Cached Images on the Fly’ is closed to new replies.