-
Notifications
You must be signed in to change notification settings - Fork 806
Hash in file name (replace index.html srcs in production, also using css) #39
Comments
You could try this plugin, which I have not tested. You'd also need some way to know what the filename is when generating the |
@Conduitry that plugin is still no longer needed (https://twitter.com/rich_harris/status/1079991930623283200). This is a serious problem. Every time I need to delete my browser cache! This can't go in production as it is. I tried with Something is moving on here: vladshcherbin/rollup-plugin-copy#21 but there are still problems with css, especially if I'm using .scss files. Any hint? |
What is it you're trying to do? I don't think it's clear yet. Seemed that you were after filename hashing (which has been solved) but not sure what the production-blocking problem is or why your browser cache is coming into question. |
Ok. Using this svelte base template I would like to use hash in file name when in production and not when in development. For this to work I need to change Using also an
in my Is the problem clear now? EDIT: I'm using It seems in rollup world nobody has been interested in it before. |
I'm also facing this problem. |
So, you guys want to have something like well, if you just set |
One solution is to hash the CSS/JS files after the static assets are built using PostHTML. After hashing, the <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Svelte Rollup Template</title>
- <link rel="stylesheet" href="bundle.css">
+ <link rel="stylesheet" href="bundle.b19ea05c629cee24e7b1.css">
</head>
<body>
- <script src="bundle.js"></script>
+ <script src="bundle.3df36d777ae1e0db2646.js"></script>
</body>
</html> |
Another option is to use @rollup/plugin-html. Here's a sample rollup config: https://github.com/Niek/obs-web/blob/master/rollup.config.js |
Here's my current rollup.config.js, with file hashing halfway figured out. I haven't found a way to hash the styles files in a way that the file would show up in the html() section to be added dynamically. Maybe someone can help with that one. I wish some of this stuff were part of the template, so I wouldn't have to figure it out for myself. Like babel, emitCss:true so there's a single style bundle, hashing and html generation, which as far as I know is the safest way to handle cache busting across deployments. But everytime I search these things, official answer seems to be "sapper does it right, use that". Hope you find this useful.
|
I used a bit of anomaly. But it works well.
This method changes
|
And what if the css is the same? Why the invalidation based on time? |
That's right. My method was based on the time of |
Thanks for your template! Note that
and add the following to the plugins array:
|
doesn't seem like rollup-plugin-css-only supports hashing |
Coming from Angular/Webpack this is such a common/basic requirement it should be available with Svelte/Rollup out of the box. I only just noticed this after several months working on a new project where I didn't find a single thing missing from Svelte but this certainly is lacking. Would it be possible for the team to bring in @metonym 's solution to this template? |
I'm working on a project that won't get high traffic but absolutely requires the latest version of every asset, so while it's not as efficient as a content-based hash, it's quick and effective with no dependencies. thanks @zidell
I agree this should be made available in the default config. While the maintainers may argue that SvelteKit / Sapper does this out of the box, I find that for a statically-hosted website (S3, Cloudflare pages, etc), using pure svelte + a basic router is incredibly effective (and a truly wonderful experience), rather than have to manually "export" the site (e.g. |
For anyone still stuck at this, I recommend you to checkout vite as a replacement for the rollup based tooling (I think it still uses rollup internally in some capacity). I've recently migrated a medium-ish plain svelte project to it and it was a breeze, and it generates some nice hashed bundles both for js and css with almost no configuration. |
I know this project uses rollup, but I came here off a search looking for file hashing in snowpack. For those using snowpack with svelte, it looks like there are a few options until snowpack itself supports this via esbuild: Plugins:
until snowpack itself supports this via esbuild: I used the first snowpack plugin above, which has the most downloads. Though the last one has zero dependencies, soooo, up to you...
My snowpack config looks like: plugins: [
'@snowpack/plugin-svelte',
[
'@snowpack/plugin-sass',
{
native: true,
},
],
[
'snowpack-plugin-hash',
// Entirely optional object. Showing default values
{
// Configured length of your hashes
hashLength: 12,
// Configure log level of plugin, 'error' | 'info' | 'debug'
logLevel: 'info',
}
],
], |
Any hint to build with hash in file name?
The text was updated successfully, but these errors were encountered: