Skip to content

Commit 4c9f309

Browse files
committed
Detect changes to static asset files
A common problem during development is that we make changes to the CSS or JS files and restart the dev server only to find that those changes haven't been picked up. This happens because we are reading those files during compilation but, after the layout is compiled, newer changes are not picked up. This commit fixes this by using the `@external_resource` attribute, which tells the Elixir compiler that the module depends on external files and must be recompiled when those change. This fixes our problem and ensures that our dev server always uses the updated assets when we make changes.
1 parent c108b23 commit 4c9f309

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/error_tracker/web/components/layouts.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ defmodule ErrorTracker.Web.Layouts do
44

55
@default_socket_config %{path: "/live", transport: :websocket}
66

7-
@css :code.priv_dir(:error_tracker) |> Path.join("static/app.css") |> File.read!()
8-
@js :code.priv_dir(:error_tracker) |> Path.join("static/app.js") |> File.read!()
7+
@css_path Application.app_dir(:error_tracker, ["priv", "static", "app.css"])
8+
@js_path Application.app_dir(:error_tracker, ["priv", "static", "app.js"])
9+
10+
@external_resource @css_path
11+
@external_resource @js_path
12+
13+
@css File.read!(@css_path)
14+
@js File.read!(@js_path)
915

1016
embed_templates "layouts/*"
1117

0 commit comments

Comments
 (0)