Js files get redirected to min.js if present

Hello all. I am new to using caddy and so far I am very impressed. I have run into a road block though which is preventing me from using the server as I would like. The issue is when I request a .js file and there is a min.js file equivalent it returns the contents of the min.js file. I have disabled the minification and then see the original file but when I enable the minification once again I see the min file. Is there a way to disable this when using the browse directive:

root …/static/build/
tls certs/cert.pem certs/key.pem

Any help would be greatly appreciated!

Thank you,

I think this is related to the gzip directive. It states that if a file has a gz version then it will automatically use that file. I am trying to us the not option to block the path but it doesn’t seem to work.

I think your question is about the minify plugin then. I’m not expert at that, but maybe @hacdias has an idea?

I’m not understanding what’s going on :confused: My plugin doesn’t do any of that (but that would be a great idea: if sth.min.js was present, it would be served instead of minifying on the fly).

@dantuck Are you using the minify directive at all? It sounds like it from your post but I don’t see it in your Caddyfile.

Sorry for a late response. As I looked further into the functionality of the automation that caddy performs I learned more that the if you have a file such as .js and then also .js.gz the gz file contents will be automatically rendered in place of the js file. As noted in the documentation:

Note that, even without the gzip directive, Caddy will serve .gz (gzip) or .br (brotli) compressed files if they already exist on disk and the client supports that encoding.

I later found a way around this functionality. Thank you everyone for your responses.

But what does a .gz file have to do with a .min.js file?

My min.js files have a .gz version. During my build process I generate the min.js file then gz it. Since the file exists caddy automatically renders the file. I noticed it was doing this process automatically after the fact.

Gotcha. So you have .min.js.gz files. Yeah, Caddy serves the minified assets by default for efficiency.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.