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

How to config use file hashing instead of query strings ? #934

Open
maimake opened this issue Jun 26, 2017 · 16 comments
Open

How to config use file hashing instead of query strings ? #934

maimake opened this issue Jun 26, 2017 · 16 comments
Assignees

Comments

@maimake
Copy link

maimake commented Jun 26, 2017

I prefer use file hashing, when I publish assets files to CDN.
Specifically, I publish assets files to CDN first, and then publish php code to my servers one by one.
So some server may be using old version assets file of CDN.

Is there a way to config use file hashing?

@dnunez24
Copy link

Agreed. It seemed to work this way in a previous version but I just upgraded and, to my dismay, we now have query strings for cache busting. I was under the impression that query strings had potential issues as a cache busting method. See other discussions of cache busting techniques and why query strings should be avoided:

https://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
https://css-tricks.com/strategies-for-cache-busting-css/
https://www.alainschlesser.com/bust-cache-content-hash/

Unless there's some new knowledge that I'm not privy to, I would strongly vote in favor of returning to the static file name with content hash as the default.

@JeffreyWay
Copy link
Collaborator

JeffreyWay commented Jun 26, 2017

I did a good bit of research and found that query string based caching should be more than adequate. Much of the research, as you linked to, is from pre-2010 and doesn't 100% apply anymore. For example, Squid has no issues anymore. If you use something like Cloudflare's CDN, you only have to click a button to activate query string busting.

There is no way in Mix 1.0 to use file-based hashing unless you want to implement it yourself within mix.then().

@dnunez24
Copy link

Fair enough. I understand that the library version is now stabilized and unlikely to make a change like that. Do you have any resources that you can point to that support your findings? I'd like to make sure I'm up-to-date as well, because two of the three articles I linked were actually from 2015 or later.

@devcircus
Copy link
Contributor

The second link provided actually recommends query strings. It also links to a maxcdn site that recommends them. Here's Jeffrey's tweet asking for feedback:
https://twitter.com/jeffrey_way/status/871052698233298944

@dnunez24
Copy link

The second link doesn't "recommend" anything. It's merely a comparison of different strategies and asking for feedback. It says that most CDNs support and recommend them, but even the example linked to from that article doesn't actually recommend anything. It simply explains how to use query strings for cache busting and how to configure the CDN to support it. I think the main trouble, in general, is that the majority of opinions on the subject are just that. There isn't much hard evidence to support a best practice without having a comprehensive review of the impact across various browsers, servers, CDNs, etc. Asking for opinions on Twitter is hardly scientific. I was hoping for some supporting hard evidence that would disprove my possibly outdated opinion on the matter.

@devcircus
Copy link
Contributor

Quoting the article

Most browsers these days will see a URL with a different query string as a different file and download a fresh copy. Most CDN's even support and recommend this.

The last sentence then links to maxcdn's recommended approach.

However you interpret that, any modern cdn supports it. A non-issue.

@devcircus
Copy link
Contributor

Also, I'm sure the Twitter question was merely a small piece of the investigation done before making a change that affects thousands of websites. I'm sure if any real issues actually ever arise, appropriate action will be taken. To now, the only evidence is second-hand info.

@maimake
Copy link
Author

maimake commented Jul 3, 2017

So, my opinion is: Let the users to choice which one to use with a configuration.

Some users maybe not use any Modern-CDN, or maybe even just use their servers instead for some reasons and no switching ability. The reality is more complex.

Hope for adding a way to fallback if it's not hard to U, as acting like pre-version Mix. So that we can update to the latest Laravel happily. Thanks

@san-kumar
Copy link

You are right about it because a lot page optimizers (including Google's) complain about using query string in static assets. I hope they add it back too.

@tomsisk
Copy link

tomsisk commented May 1, 2018

I don't really think this is a "non-issue". There are cases where you need both versions of the code, mainly during a deployment to multiple servers. We are doing one-at-a-time deployments to about 10 servers. We send our assets to S3/Cloudfront before deploying any backend code. In most cases, this probably isn't an issue. There are a couple different types of users that can hit the site during a deployment:

  1. Everyday user.
  2. A new unique user.

User 1 should have no issues, the old version will very likely be in their browser cache, so they can continue to use the site on whatever code is on the back end server they happen to be hitting. User 2, however, is only fine if the old cached version exists in the Cloudfront edge they are hitting. If it does not, they have new assets with old backend code, which is potentially a messed up site. Granted, this should only be for a few minutes max, but it's not exactly the ideal situation I want to show new users.

That is with a CDN in front. Remove that, and the problems become much worse. User 2 could end up caching old assets with the new hash.

Perhaps our deployment strategy is garbage. I know there are other options here, but not without either losing server power or adding it during a deployment (neither of which I think are ideal, but options nonetheless). Hashed file names just work in so many more different situations.

@octoxan
Copy link

octoxan commented Oct 24, 2018

Really disappointed in this solution as query string cache busting doesn't work 100% of the time for our users. Shouldn't have to tell a client to shift refresh to see changes. Changing the file name works, query strings do not. Should at least be an option.

@terryupton
Copy link

Any update on this? is this feature/option likely to make it into Mix?

@Lukasz93P
Copy link

If someone tells that "query string is enough" then I have one question - what about rolling updates??
If I have many web servers I can have the best CDN which supports query string but I can't deal with situation when part of servers has the never version and some of them not.

If versioning was using hashing not query string I could do it like that:
Upload new versions to the shared object storage like S3 during/just before deploy and then everything would work fine, but with you "more than enough" solution it's not possible.

@thecrypticace
Copy link
Collaborator

thecrypticace commented Sep 27, 2021

If you're using a CDN that handles long-term asset caching based on query string then the old version will be in the cache even after you upload the new file. This will handle rolling updates appropriately.

Having said that there are other reasons that using file name versioning could be a good idea like the ability to use an immutable cache and protection from file/image/etc… name collisions during the build process. re: asset collisions — file-named versioning is the only real solution to this problem as such I think it'd be reasonable to at least add an option to enable it for everything if we're going to enable it there. However, most use cases do not need it and I see no reason to change the default if we do make this configurable.

I'm going to re-open this and possibly make it an option in Mix v6.1

@jonaslm
Copy link

jonaslm commented Apr 13, 2022

How is this coming along? We've started seeing some users running Edge where the browser is ignoring the querystring cache busting entirely and keeping the old copy cached instead. As someone mentioned above, it's embarassing having to tell clients to force-refresh to fix these issues.

@szepeviktor
Copy link

szepeviktor commented Jun 16, 2022

We - old people - use query strings to input data into a web application.
Static files should have a unique and changing URL.

I use a webserver rule that strips out version from URL path: /js/app.1234.js it becomes /js/app.js in the filesystem.

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

No branches or pull requests