VersionedAssets
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.
Description
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.
Installation
Download versioned_assets.phpΔ and put it into your cookbook/
directory. Then add such a line to config.php
:
include_once("$FarmD
/cookbook/versioned_assets.php");
Configuration
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;
Usage
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.
Notes
Versioned Assets should work equally well with
on or off, and also with SecureAttachments configured. However, I have not tested all of these possibilities.
$EnableDirectDownload
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.
Contributors
Comments
See discussion at VersionedAssets-Talk.
F.A.Q.
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.
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.