Speed up API in Dev: Move Code Reloader to Browser Pipeline

I've been working on my GraphQL API, and found that all of the code reloaders/checks ran on every endpoint call, which cause ~1-3s delay on every API request! I moved the following plugs from endpoint.ex to router.ex:

pipeline :browser do
  if Application.compile_env(:my_app, [__MODULE__, :code_reloader], false) do
    plug Phoenix.LiveReloader
    plug Phoenix.CodeReloader
    plug AshPhoenix.Plug.CheckCodegenStatus
    plug Phoenix.Ecto.CheckRepoStatus, otp_app: :my_app
  end

  # ...
end

Now, I get instant API calls in development. In my case, there really isn't a downside because I test with GraphiQL, so I still get the code reloading via that. YMMV. 🚀
Was this page helpful?