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

Keep links stable for static assets while retaining cache busting #1196

Open
choldgraf opened this issue May 9, 2024 · 0 comments
Open

Keep links stable for static assets while retaining cache busting #1196

choldgraf opened this issue May 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@choldgraf
Copy link
Member

Currently when static assets are linked to a MyST site build, their URL gets generated with a hash that is part of the filename. This is done to ensure that the cache is busted if the file is updated.

For example, using {download}`myfile.png` results in a filename like mysite.org/build/myfile-c7e3595ff6c09f5cc22cc52b8177cd4c.png)

The problem with this is that if you want to directly link to a static asset elsewhere, the link will be invalidated as soon as the MyST site is rebuilt, because the hash is included in the filename itself.

It would be useful if the URL for static assets was persistent as long as the user didn't change the filename, so that external links to them remained valid.

Potential solution: cache busting

One option is to use a query parameter to bust caches, rather than putting the hash in the filename.

Essentially you'd move the hash from this:

mysite.org/build/myfile-c7e3595ff6c09f5cc22cc52b8177cd4c.png

to this:

mysite.org/build/myfile.png?v=c7e3595ff6c09f5cc22cc52b8177cd4c

The hash becomes part of a "query" parameter. You can thus still link directly to the file (mysite.org/build/myfile.png) and links on the MyST site will include the hash via the query parameter so you'll cache-bust as expected.

References

@choldgraf choldgraf added the enhancement New feature or request label May 9, 2024
@choldgraf choldgraf changed the title Keep links stable for static assets Keep links stable for static assets while retaining cache busting May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant