Attache-ImageSizer-Talk

Summary: Talk page for Attache-ImageSizer.
Maintainer: Eemeli Aro
Users: (View? / Edit)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.

This recipe was causing a problem where images on the wiki were not being cached by the browser, at all. Here is how I solved it:

Near top of recipe added:

 SDV($AllowBrowserImageCaching, true);

In function HandleImageDownload, to the end of the first line of the function (the list of globals), I added:

 $AllowBrowserImageCaching;

In function HandleImageDownload, just before this line

 	## file read & delivery based on HandleDownload

I added this:

	if ($AllowBrowserImageCaching == true) {
		header('Cache-Control: max-age=2592000');
		header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000)); // 1 month
		header_remove('Pragma');
	} else if (IsEnabled($EnableIMSCaching, 0)) {
		header('Cache-Control: private');
		header('Expires: ');
		$filelastmod = gmdate('D, d M Y H:i:s \G\M\T', filemtime($filepath));
		if (@$_SERVER['HTTP_IF_MODIFIED_SINCE'] == $filelastmod)
			{ header("HTTP/1.0 304 Not Modified"); exit(); }
		header("Last-Modified: $filelastmod");
	}

What this does:

  1. If $AllowBrowserImageCaching is set to true (the default), then HTTP headers are set to instruct the browser to cache the image for a month.
  2. Otherwise, if $EnableIMSCaching is enabled, then HTTP headers are set to allow If-Modified-Since caching.

Said Achmiz November 03, 2017, at 03:16 AM

Eemeli no longer maintains the recipe, if you like, and if you think your changes will benefit others without breaking existing installations, feel free to take over the maintenance. A small note about the above: You can use any variable names you like but most of the on/off variables in PmWiki are named $EnableSomething, eg $EnableBrowserImageCaching. I would NOT enable it by default (people may and do re-upload retouched pictures), and I'd probably make the cache delay configurable (probably in days, eg $ImageCachingDays = 30;) --Petko November 04, 2017, at 03:12 AM

Ah, ok, didn't know it was not maintained. I think I will make the changes you noted and do some testing and if it seems to work and not cause problems, I will upload the new version and maintain it. Thanks for the pointers! —Said Achmiz November 04, 2017, at 02:31 PM

Talk page for the Attache-ImageSizer recipe (users?).