Questions answered by this recipe
If your wiki’s webserver is properly configured (i.e. sends cache-control headers properly), then images and other attachments will be cached by visitors’ browsers (so that visitors to your site don’t have to download the same images/etc. over and over when they visit a page multiple times). This is good, and makes your wiki feel faster and more responsive.
But what happens you modify or update an attachment, or upload a new version? Repeat visitors who have the old version cached, will still see the old version… unless you have versioned assets. That’s what this recipe adds.
Versioned Assets appends, to the URLs for attachments (a.k.a. “attachlinks”), a URL parameter containing the modification time of the uploaded file (assuming the file exists, of course). This means that when an uploaded file is modified, or when a new version is uploaded, the URL of the attachlink will automatically update. A browser that has the old version of the file cached, will see the changed URL, and will retrieve and display the new version, instead of showing the old version.
Git repository for this recipe: https://git.sr.ht/~achmizs/pmwiki-versioned-assets.git.
There is one configuration option:
$VersionedAssetsReattachFileExtension (defaults to
true). It causes an uploaded file’s extension to be appended to the version string that’s added to the attachment link URL. (This is so that LinkIcons, and similar things that check whether a link ends in a particular file extension, can continue to work properly.)
To disable this behavior, add the following line to
config.php (before including the recipe):
$VersionedAssetsReattachFileExtension = false;
You don’t need to do anything special once Versioned Assets is installed; all attachment links (generated by
Attach: markup) will automatically include the version in the URL.
This recipe may be incompatible with certain other recipes that change how
Attach: markup is handled, or how attachment links are generated.
Change log / Release notes
- 2021-12-12: Minor fix.
- 2017-12-13: Initial release.
See discussion at VersionedAssets-Talk.
Will old links to an attachment still work, when a new link is generated? (e.g. if someone saves the direct link to an attachment on my wiki) Or do old links stop working?
Old links (those with a previous version parameter in the URL) continue to work, but someone who has an old link may see an old (cached) version of an updated attachment.
If someone omits the version parameter from a link to an attachment on my wiki, will the link work?
Yes, the link will work, but again, someone with a version-less link may see an old (cached) version of an updated attachment.