Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-12-04 00:58:16

JanDW
Plugin Author
From: Providence, RI, USA
Registered: 2008-07-18
Posts: 327
Website

images query params for caching / build scripts

Is there any way to have textpattern add query params to when listing images for caching purposes? e.g. <img src=”/images/13.png?v1 />” in case I’ve replaced the image?

On a related note, does anybody have some sort of build script that works with textpattern that e.g. autmatically adds a query param to css files and such when they push a new iteration of a site live?
Curious to know what you guys use…


TXPDream – A Textpattern Tag Library for Adobe Dreamweaver. (updated for 4.2.0) | jdw_if_ajax – Only serve certain parts of a page when requested with AJAX

Offline

#2 2010-12-04 09:00:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,273
Website GitHub

Re: images query params for caching / build scripts

JanDW wrote:

Is there any way to have textpattern add query params to when listing images for caching purposes? e.g. <img src=”/images/13.png?v1 />” in case I’ve replaced the image?

I’ve used a pretty standard technique in smd_thumbnail which appends the file’s modification timestamp on the end. Thus when the file is updated a new query string is generated and (in theory) the browser will not use the cache for that first request.

But you’ll probably have to build the entire thing in PHP as I don’t know if it can (easily) be done by adding stuff after the fact:

<txp:images category="some-cat">
<txp:php>
   global $path_to_site, $img_dir;
   $impath = $path_to_site.DS.$img_dir.DS.image_info(array('type' => 'id')).image_info(array('type' => 'ext'));
   $uDate = '?'.filemtime($impath);
   echo '<img src="' . image_url(array()).$uDate. '" />';
</txp:php>
</txp:images>

Something like that anyway.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB