The performance (loading speed and bytes sent) of a website can be optimized using Yahoo’s API “Smush.it” by optimizing images in several losless ways:
- stripping meta data from JPEGs
- optimizing JPEG compression
- converting certain GIFs to indexed PNGs
- stripping the un-used colours from indexed images
The WordPress plugin “WP Smush.it” does an awesome job by automating this process and offering a bulk action to smush all images. Unfortunately the Yahoo service isn’t very reliable nor fast, and that’s an understatement.
A lot of users are experiencing delays causing the plugin to be disabled. The following error is thrown:
Timeout
I found out that the delay of 20 seconds is not enough 90% of the cases. After increasing the timeout to 180 seconds (3 minutes) the automatic smushing didn’t got disabled anymore (after 6 months testing).
Currently there’s no setting in the WordPress plugin to change the timeout, I’ve contacted the author and requested this feature. For now you need to edit the file wp-content/plugins/wp-smushit/wp-smushit.php and change the timeout in line 280 from 20 seconds to 180 seconds.
Original:
$response = wp_remote_get($req, array('user-agent' => WP_SMUSHIT_UA, 'timeout' => 20));
Example:
$response = wp_remote_get($req, array('user-agent' => WP_SMUSHIT_UA, 'timeout' => 180));
Keep in mind that increasing the timeout could delay the process of smushing the images and therefor uploading your article.
Hi,
Is it also possible to change this rule with functions.php so this change stays available also when there is new version of smush.it?
Kind regards,
Willem
Hi Willem,
Unfortunately I don’t see how this can be implemented in funcions.php, the timeout is directly in the wp_remote_get.
You could alter the wp_remote_get function and force a longer timeout, but I would seriously discourage anyone to do that. It would affect all functions that use this function.
Let’s hope the author increases the timeout in the next release and/or make it configurable.
Cheers,
Ingmar
Update 12 march 2013
Yesterday the author updated the plugin to version 1.6.1, the changelog only states “no longer maintained notice”. The proposed solution was not implemented.
On 15 march the author updated the plugin to version 1.6.3 and added a setting to configure the timeout.
Changelog: http://wp.me/a1A0aH-1fc
Example: http://wp.me/a1A0aH-1fd
Yeah! Good thing :-). Thanks for the notice.
Version 1.6.3 has a minor bug causing “Error posting to Smush.it” for new images.
This is easily solved by removing the following code on line #330 in wp-smushit.php:
$data = FALSE;
Version 1.6.4 is released, this fixed the problem mentioned above.
Is there a way to cache APIs?
What do you mean with caching an API? Can you explain what you want to cache?
Looks like the maximum value that can be set via Settings/Media is 60. Higher values are changed to 60 on save.