fuse-box-examples icon indicating copy to clipboard operation
fuse-box-examples copied to clipboard

Support hashing of bundles for cache breaking

Open mattoni opened this issue 8 years ago • 3 comments

Hi everyone,

So a very common set up is to hash bundles so that the client can cache them, but download new content whenever the bundle is updated ( and therefore will have a new hash ). However, we need to know the names of the files generated in order to serve them properly. I think I saw before that there was support for a hash() method on the "factory", but I may be mistaken.

In order to support this, I propose a hash option be added to a bundle config, with the type of hashing desired.

fuse.bundle("client/app")
    .watch("client/**")
    .hmr()
    .hash("md5")
    .instructions(" > client/index.ts");

then, we need the ability to get the names of bundles created. I was thinking as an async return from run, but if we're in watch-mode that may present some challenges, so I'm not sure the best way to retrieve the generated bundle names. Any input is welcome.

Thanks!

mattoni avatar Mar 20 '17 23:03 mattoni

Great! hash : option is already in place https://github.com/fuse-box/fuse-box/issues/350

I think run.then could return some meta information, for sure. As it's needed only for production builds, therefore we don't need to care about watching, right?

nchanged avatar Mar 23 '17 21:03 nchanged

Maybe, my goal would be to get something like a manifest.json that I can use in my templates to refer to the file name from there without manually programming it in, so getting it in dev mode would be useful as well.

At the end of the day, I want to do client bundle splitting with hashed bundles, so they can be cached on the browser side. but the less separate config for dev vs prod the better.

mattoni avatar Mar 23 '17 21:03 mattoni

We've had some ideas on code splitting. It all comes down to a master bundle right? It is aware of its children.. or slaves.

import("home", module => {})

whereas home is home.e5e5e7h3.js and this information is stored in the primary bundle. So all I am saying is that fusebox should be able to write this information automatically. Correct me if I am wrong here.

nchanged avatar Mar 23 '17 21:03 nchanged