I thought about adding a
js format to the
accepts plug and a
foo.js.eex template, and interpolating Elixir variables in the template. But this approach has several draw backs:
- I can’t embed the route in a
scripttag without using
?_format=js, which seems strange. For example:
- Phoenix raises an error and asks me to disable request forgery for js requests. This means I need a separate pipeline for JS routes.
Another way is to add the identifying data to data attributes and use the same file. For example:
<script src="path_to_file.js" data-slug="foo" data-type="bar" etc...></script>
Then from within the file I would get those data attrs. I haven’t tested this, so I’m not sure how well it would work.
What’s a better way to do this?