Replace per-request timestamp cache-busting with file mtime versioning for media URLs#1706
Replace per-request timestamp cache-busting with file mtime versioning for media URLs#1706
Conversation
Co-authored-by: Woseseltops <1909317+Woseseltops@users.noreply.github.com>
Co-authored-by: Woseseltops <1909317+Woseseltops@users.noreply.github.com>
Co-authored-by: Woseseltops <1909317+Woseseltops@users.noreply.github.com>
|
@vanlummelhuizen susan suggest you also review this, you agree? |
|
My assessment is that the url parameter Reasoning:
And this view does not use any url parameter. If my assessment is correct, CoPilot is just making stuff up and is basically wasting our time. |
|
You and Jetske were the ones that added the " |
|
If I was working on this, I probably would have removed the existing "now" code and instead when a new video is uploaded dynamically stick that into the template using jQuery and force the page to reload. (Which sounds like a bad solution.) You can see on the gloss_videos.html page (video buttons branch #1686) that I added this "now" and forced the page to reload (a lot). So whatever solution ends up implemented is needed there too. I have yet to test this solution. |
|
Reassessment: What I now realize is that the Copilot's proposal is an option, but I don't know if checking the mtime is the best solution. An alternative is adding the ID of the GlossVideo in the @susanodd @Woseseltops what do you think is the best solution? |
|
I like that idea! I am trying to use CoPilot's solution but something broke with fetching the videos when combined with the new functionality for restoring a video. (Now it's fetching a video with "bak" in the name for some reason. So something happened to the path. Probably I did not merge it correctly.) |
|
Quick summary:
If the solution by @vanlummelhuizen works it seems cleaner to me |
?v={% now 'YmdHis' %}appended to every video/image URL generated a new cache key on every page load, effectively disabling browser caching for all media assets.Changes
New
media_versiontemplate filter (signbank/dictionary/templatetags/cache_control.py): returns the file's mtime as an integer. AcceptsFileFieldobjects (via.path) or URL-encoded path strings (decoded and resolved againstWRITABLE_FOLDER). Returns0on failure.gloss.htmlandgloss_detail.html: replaced all 15 occurrences of{% now 'YmdHis' %}with|media_version. Also removed the cache-busting parameter from external source URL hyperlinks where it was semantically meaningless.The filter falls back to
0when a file is missing, keeping URLs well-formed without breaking anything.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.