Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Append query string to URLs of files in local volumes to bust the browser's cache when the file changes #5824

Open
benface opened this issue Mar 20, 2020 · 5 comments

Comments

@benface
Copy link
Contributor

@benface benface commented Mar 20, 2020

It seems the Amazon S3 plugin (and maybe others) already do this, but not the core Local volume type. When someone replaces an image in a local volume, and the front-end of the site displays that image like this: <img src="{{ image.url }}">, the URL remains the same, meaning that if the image was already cached by a browser, it will keep displaying the old image until the cache is cleared. It would be nice if getUrl() appended a query string representing the file's last modified date or the file's hash to force the browser to re-download the image.

@juddlyon

This comment has been minimized.

Copy link

@juddlyon juddlyon commented Mar 20, 2020

Agreed - I have authors that run into this and I have to tell them to rename the file.

@brandonkelly

This comment has been minimized.

Copy link
Member

@brandonkelly brandonkelly commented Mar 20, 2020

We can consider adding this to core, but in the meantime you can use the Asset Rev plugin to accomplish this.

Or just manually add a query string param to the URLs using the url() function:

<img src="{{ url(image.url, {v: image.dateModified.timestamp}) }}">
@benface

This comment has been minimized.

Copy link
Contributor Author

@benface benface commented Mar 20, 2020

Thanks @brandonkelly, unfortunately the Asset Rev plugin doesn't really support that use case at the moment but I created a FR there too: clubstudioltd/craft-asset-rev#27

@brandonkelly

This comment has been minimized.

Copy link
Member

@brandonkelly brandonkelly commented Mar 20, 2020

@benface just edited my last comment, fyi

@benface

This comment has been minimized.

Copy link
Contributor Author

@benface benface commented Mar 20, 2020

Oh that's a nice solution, I would suggest adding this to the docs @mattstein.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.