{"action":"created","issue":{"url":"https://api.github.com/repos/parcel-bundler/parcel/issues/717","repository_url":"https://api.github.com/repos/parcel-bundler/parcel","labels_url":"https://api.github.com/repos/parcel-bundler/parcel/issues/717/labels{/name}","comments_url":"https://api.github.com/repos/parcel-bundler/parcel/issues/717/comments","events_url":"https://api.github.com/repos/parcel-bundler/parcel/issues/717/events","html_url":"https://github.com/parcel-bundler/parcel/issues/717","id":293262122,"number":717,"title":"🙋 Use MD5 of File Content As Name To Bust Caches","user":{"login":"benhutton","id":61645,"avatar_url":"https://avatars2.githubusercontent.com/u/61645?v=4","gravatar_id":"","url":"https://api.github.com/users/benhutton","html_url":"https://github.com/benhutton","followers_url":"https://api.github.com/users/benhutton/followers","following_url":"https://api.github.com/users/benhutton/following{/other_user}","gists_url":"https://api.github.com/users/benhutton/gists{/gist_id}","starred_url":"https://api.github.com/users/benhutton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benhutton/subscriptions","organizations_url":"https://api.github.com/users/benhutton/orgs","repos_url":"https://api.github.com/users/benhutton/repos","events_url":"https://api.github.com/users/benhutton/events{/privacy}","received_events_url":"https://api.github.com/users/benhutton/received_events","type":"User","site_admin":false},"labels":[{"id":774284799,"url":"https://api.github.com/repos/parcel-bundler/parcel/labels/%23Feature","name":"#Feature","color":"c2e0c6","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2018-01-31T18:21:44Z","updated_at":"2018-02-01T16:43:25Z","closed_at":null,"author_association":"NONE","body":"This is something my team is interested in implementing, but want to make sure we're not heading in the wrong direction...\r\n\r\n### 🤔 Expected Behavior\r\n\r\nIn order to serve assets through a CDN, we need to use a hash of the file contents as part of the filename. This is the only way to ensure that cache busts at the right time and only at the right time. \r\n\r\n - `mtime` changes based on developer machine / git checkout\r\n - etags don't work with CDN\r\n - query string approaches don't work with all proxies\r\n - the current approach never cache busts on content change\r\n - some sort of random string (current time, or build time, or something) would bust too often\r\n - manual versioning of the entire build (ie, output to /dist/v2) is annoying and busts too often\r\n - manual versioning of individual files (ie, app-v2.js) is really annoying\r\n\r\nThis issue has been discussed extensively here: https://github.com/parcel-bundler/parcel/issues/188.\r\nWe have discussed it a bit on slack start here: https://parcel-bundler.slack.com/archives/C8QC15PNY/p1515609163000373\r\n\r\nTo be specific, I am proposing files be named `${contentHash}.${ext}}`\r\n\r\n### 😯 Current Behavior\r\n\r\nCurrently, the filename is a hash based on the _name_ of the file (and some options like whether or not hmr is enabled, I believe). Something like `${fileNameHash}.${ext}}`\r\n\r\n### 💁 Possible Solution\r\n\r\n@shawwn proposes parts of the solution here: https://github.com/parcel-bundler/parcel/issues/188#issuecomment-353141569\r\n\r\n@Munter describes how tree traversal needs to work to make the cache bust in all the right places here: https://github.com/parcel-bundler/parcel/issues/188#issuecomment-357072153\r\n\r\nOne key piece of the puzzle will be to only enable this behavior on `build` (ie, when building for production). Leave it off in the development modes, so you don't have to worry about \r\n\r\n### 🔦 Context\r\n\r\nWe want to serve our assets (css, js, images) through a CDN like CloudFlare or CloudFront. If something about the url doesn't change, then new versions of those assets will never make it to the end user. If too much changes, then we bust the cache too aggressively.\r\n"},"comment":{"url":"https://api.github.com/repos/parcel-bundler/parcel/issues/comments/362325836","html_url":"https://github.com/parcel-bundler/parcel/issues/717#issuecomment-362325836","issue_url":"https://api.github.com/repos/parcel-bundler/parcel/issues/717","id":362325836,"user":{"login":"benhutton","id":61645,"avatar_url":"https://avatars2.githubusercontent.com/u/61645?v=4","gravatar_id":"","url":"https://api.github.com/users/benhutton","html_url":"https://github.com/benhutton","followers_url":"https://api.github.com/users/benhutton/followers","following_url":"https://api.github.com/users/benhutton/following{/other_user}","gists_url":"https://api.github.com/users/benhutton/gists{/gist_id}","starred_url":"https://api.github.com/users/benhutton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benhutton/subscriptions","organizations_url":"https://api.github.com/users/benhutton/orgs","repos_url":"https://api.github.com/users/benhutton/repos","events_url":"https://api.github.com/users/benhutton/events{/privacy}","received_events_url":"https://api.github.com/users/benhutton/received_events","type":"User","site_admin":false},"created_at":"2018-02-01T16:43:24Z","updated_at":"2018-02-01T16:43:24Z","author_association":"NONE","body":"@devongovett this is where I'm still a bit hazy and hoping ya'll can offer me some pointers. I see it all as depending on how tree traversal happens at the packaging level, and I'm not really straight on how that happens.\r\n\r\nAssuming tree traversal happens the right way (namely, like this: https://github.com/parcel-bundler/parcel/issues/188#issuecomment-357072153, hitting child nodes before parent nodes),\r\n\r\n- Child nodes have no references to anything else. So they hash themselves and save.\r\n- Parent nodes reference the child nodes. So re-write those references first. Then hash themselves and save.\r\n- Repeat as you walk your way back up the tree.\r\n\r\n"}}
{"actor":{"display_login":"benhutton"}}