caddy -version)?0.10.13
I want to avoid having to declare each and every file that should be pushed for a particular route.
Preferably by specifying a directory or some regex specifying matching files.
@dahankzter thanks for the feature request.
Can you provide some use cases where this would be useful? I will make it easier to prioritise this possible feature.
Also with some argument that the performance tradeoff is worthwhile.
Just to note @dahankzter you can have your server set a Link header with all the assets needed to push for each route. If you're using some framework for your application, you could write/use a plugin that keeps track of assets you add to pages then when flushing your response you can add the Link header with all the assets included.
I don't disagree that this feature might have some use, but I think generally it can be solved at the application level rather than with Caddy directives, more effectively.
This came up when I deployed a Hugo generated site and I just wanted to push some static assets.
I quickly realised I had no idea which resources the generated site wants to serve either javascript or css.
After some firefox network inspection I could find a number of resources but it would have been very neat to just specify "/js" or "/css" and perhaps a logo or so.
It's more of a convenience really because everything I want to do is possible only the config ergonomics are lacking.
What I mean is that if I have a custom app where I have full control of what gets served and when I can push myself or use the Link directive. Now I have only a blob of html and resources to serve.
Personally it would seem to me that the strength of _http push_ comes in only pushing assets that are needed, so a general push everything in a directory would not necessarily have my vote to implement.
They were all needed on all pages so that prerequisite was met. And like I said it was a generated site where control is very limited.
The idea of having Caddy at all is diminished when having a custom own app. Proxy and static sites are what it's for and providing directories instead of a list of messy files seems very good.
What if the theme I use for Hugo decides to use some other js library or split up the css in different files then I have to fix the Caddy push config as well.
They were all needed on all pages so that prerequisite was met. And like I said it was a generated site where control is very limited.
Except it doesn't account for browser cache...
I'm only mildly excited about server push in the first place, and less so about pushing _all the things_. I think the site owner needs to be very deliberate about what to push in order for it to be effective.
Perhaps it's overrated and normal classic edge caching at a cdn is better.
But allowing the config can make sense anyway since it would make a rapidly developing site (that wants to push) less prone to constant config changes which _will be forgotten_ sooner or later.
Is it a difficult change that carries a lot of potential risk and maintenance?
I'm not entirely convinced... sites _in dev_ certainly don't need the performance demands of server push, let alone pushing a whole directory.
Most features like this tend to creep up in complexity more than forethought. So, I appreciate the feature request -- but I think we're not going to do it at this time. Thanks!
I was also looking for this, for a static web application has resources that have a cache-busting short-hash in their filenames. We cannot use a static configuration like:
push / {
/assets/fonts/MaterialIcons-Regular.570eb8.woff2
/assets/chunk.1.ba24f9.css
/assets/chunk.2.ba24f9.js
}
where those hashes are different every time we deploy a new version.
I solved this by having a script generate a file that has the above configuration and then have the main Caddyfile import it. Heavily inspired by https://github.com/detroitenglish/caddy-push-webpack-plugin but instead of generating the file using a Link header, I generate a file with the push directive.
How a server (as opposed to an actual app) is configured to know which resources to push is -- across all the servers -- a hard problem to solve well.
@schmkr If sky was the limit, how would you like to see this done in Caddy 2?
Most helpful comment
I was also looking for this, for a static web application has resources that have a cache-busting short-hash in their filenames. We cannot use a static configuration like:
where those hashes are different every time we deploy a new version.
I solved this by having a script generate a file that has the above configuration and then have the main Caddyfile import it. Heavily inspired by https://github.com/detroitenglish/caddy-push-webpack-plugin but instead of generating the file using a
Linkheader, I generate a file with thepushdirective.