[MGNLUI-340] Images and assets should be cached on client until there is a new version of the asset Created: 05/Dec/12  Updated: 17/Jun/13  Resolved: 07/Jan/13

Status: Closed
Project: Magnolia UI
Component/s: None
Affects Version/s: None
Fix Version/s: 5.0

Type: Bug Priority: Blocker
Reporter: Christopher Zimmermann Assignee: Christopher Zimmermann
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
dependency
depends upon MGNLDAM-77 Add lastModified to Asset types Closed
depends upon MAGNOLIA-4759 Provide method to add a fingerprint t... Closed
depends upon MGNLSTK-1063 InternalAssetVariation should add a f... Closed
relation
is related to MGNLUI-346 Assets App: All instances of an image... Closed
is related to MGNLIMG-103 Set a header on responses instructing... Closed
is related to MGNLIMG-105 Ensure that images are set to cache i... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:

 Description   

For M5 Alpha1 we are setting images headers to no cache so we always see the changes when images are edited (http://jira.magnolia-cms.com/browse/MGNLIMG-103) But this is bad for performance.

First part of this ticket is to remove the no-cache header.
One implementation strategy for this ticket is to append a querystring to the asset with the modification date (or a key, derived from it) so that the asset can be cached by browser and proxy, but when the asset is modified, then the client loads the new asset.

Part of the solution may be in Imaging Module, but putting it in here for now.Move ticket if needed.



 Comments   
Comment by Christopher Zimmermann [ 03/Jan/13 ]

To achieve this, the internets recommend changing the name of the file, rather then adding a query string. This technique is called "fingerprinting" because you give the file a unique name to match the content. Im opting to use the lastModified date for the fingerprint, though there are recommendations to use an md5 hash of the content so that the fingerprint really only changes when the data changes. This seems more complicated then is really necessary.

Comment by Christopher Zimmermann [ 03/Jan/13 ]

Resources:
https://developers.google.com/speed/docs/best-practices/caching
Recommendations: "Dont include a querystring in the URL for static resources" Squid up through version 3 do not cache resources with a ? in the url.

http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
http://guides.rubyonrails.org/asset_pipeline.html

Comment by Christopher Zimmermann [ 03/Jan/13 ]

call addAssetCacheFingerprintToLink in getGeneratorImagePath.
Remove the cachebusting querystrings in VThumbnail and Actionbar.
Make sure an assets modificationDate is changed when it is saved (in SaveFormAction).

you can test that this works be cropping an asset in the assets app, then see that the thumbnail and preview are updated with the new image. (because of the updated url of the images.)

Comment by Federico Grilli [ 03/Jan/13 ]

Reopened after review.
Could you please format the code according to our code style guidelines? There's an epf attached to this page http://wiki.magnolia-cms.com/display/DEV/Code+Style which you can import into your Eclipse. It will automatically format code and order imports upon saving. Or you can just select the file you wish to reformat, right-click -> Source -> Clean up…

One minor remark: in LinkUtilAsset it's maybe better to use http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/time/FastDateFormat.html as a class level formatter (it is thread-safe) rather than instantiating each time java.text.SimpleDateFormat in addAssetCacheFingerprintToLink(..) which, iirc, has some performance issues.

Comment by Christopher Zimmermann [ 07/Jan/13 ]

Applied formatting.
Changed static final property based on FastDateformat instead of SimpleDateFormat for stability and performance reasons.

Generated at Mon Feb 12 08:35:55 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.