Dev environment slow response time caused by priv/static files

After I added static files to a new Phoenix project, non-static requests started responding slowly above 7 seconds in my local dev environment.

This answer elixir - Phoenix slow response time - Stack Overflow pointed me to the static folder.

I had a node_modules folder in priv/static that was over 80 MB. If I move the node_modules folder out of priv/static, requests respond normally. The files I removed are continue to get served because a copy of the node_modules folder is in _build/dev/lib/[app_name]/priv/static.

What is Phoenix or Plug doing on every request with priv/static and the _build folder?

The priv/static directory is the directory from which it serves static content, like images. You can usually find something like this in your Endpoint module

  plug(Plug.Static,
    at: "/",
    from: :coffee_time,
    gzip: false,
    only: CoffeeTimeWeb.static_paths()
  )

node_modules definitely doesn’t belong there and it has a bazillion tiny files in it which will definitely slow things down. Plug.Static is gonna be checking to see if those has changed on request.

Requests to the home page controller serving a HEEx render is slow.

Does Plug.Static check every file in priv/static for non-static requests?

Your homepage likely includes a synchronously loaded css file, which is a static asset.

The homepage can be a blank HEEx file and request responds in 7 seconds if the node_modules folder is in priv/static.

How does it know a request isn’t static? It first matches on all static values and if a value doesn’t match, it then gets forwarded on to the router.

But there‘s a whitelist of allowed folders/files (by default at least). I would imagine this to be checked quickly.

Static files respond normally when the node_modules folder is in priv/static.