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

Use a hash in js filenames for all environments #271

Closed
wants to merge 1 commit into from

Conversation

mikeyhew
Copy link
Contributor

Fixes #267

@gauravtiwari
Copy link
Member

@mikeyhew Apparently, we can't use [chunkhash] in conjunction with webpack-dev-server so, an alternative would be to use [hash] in shared.js and keep production.js as it was earlier. Someone from webpack team commented on similar issue so, I am not sure if we should have this since after #264 there will be only webpack-dev-server and no watcher -

You should not use [chunkhash] or [hash] for development. This will cause many other issues, like a memory leak, because the dev server does not know when to clean up the old files.

webpack/webpack-dev-server#377 (comment)
webpack/webpack#1363 (comment)

@p0wl
Copy link
Contributor

p0wl commented Apr 20, 2017

more than that, it will not work because of a conceptual problem:

bin/webpack-dev-server (and bin/webpack) updates the manifest.json when the compilation is finished. If you refresh before the compilation is finished, rails uses the old manifest.json, which points to the old file names (old hashes). I guess rails handles this by waiting to render the script tag until the compilation of the requested file is done (?).

I think the right way to go would be to set the headers for every file in public/packs to something like Cache-Control: no-cache, no-store, must-revalidate in development.

@mikeyhew
Copy link
Contributor Author

@gauravtiwari That's... interesting. I changed my app's config today to put a hash in the filename, just like in this PR, and it works really well. Although I just checked my public/packs folder and there's a hundred different files in there 😆

That comment farther down by @SpaceK33z is pretty naive though. I have some remote assets that aren't stored on my local machine, and the browser saves a lot of bandwidth by caching them. It especially helps when you're tethering your phone and want to minimize data charges.

No, you should have every caching feature off in dev. There's no real benefit; you're working on localhost anyway, so downloading is only limited by your imagination disk.

@mikeyhew
Copy link
Contributor Author

@p0wl

I think the right way to go would be to set the headers for every file in public/packs to something like Cache-Control: no-cache, no-store, must-revalidate in development.

If that works, it would be a fine solution.

@gauravtiwari
Copy link
Member

@mikeyhew Btw, you have been using watcher or dev server in development?

@dhh
Copy link
Member

dhh commented Apr 20, 2017

Sprockets doesn't include a hash in development either. Relies on cache controls. We should do the same.

@dhh dhh closed this Apr 20, 2017
@rafaelfranca
Copy link
Member

Sprockets doesn't include a hash in development either. Relies on cache controls. We should do the same.

It actually does since Rails 4.2,, but it relies on cache controls.

@mikeyhew
Copy link
Contributor Author

@gauravtiwari I'm using watcher. I tried using the dev server, to see if it would stop things from being cached, but I think it still had the same problem.

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

Successfully merging this pull request may close these issues.

None yet

5 participants