shortlyportly
Javascript on a single (or several) pages only
Hi All.
I’m developing an app using Phoenix and I want to include a JavaScript library on specific pages (don’t want to load it on those pages that don’t need it). Is there a standard way to achieve this?
cheers
Dave
Most Liked
idi527
The easiest way is probably to split it into a separate script and put
<script src="new_script.js"></script>
only on the pages where you want it.
OvermindDL1
What I do on my polymerized pages is I pass a extra_javascript option to the assigns being a list of what extra javascript to bring in for a page to work, and my primary view just loads those in, in-order, after my app.js as well.
But really, get rid of jQuery, it is not useful anymore and if you want the functionality there are shims that are much faster now too.
shortlyportly
My fault for no explaining my issue correctly but the library I’m using relies on Jquery which gets loaded at the end of app.html.eex so just including my script in the relevant page doesn’t work as Jquery is loaded yet.
I don’t want to include my script in app.html.eex for all pages as it is rather large and only required for a few pages (for reference it is a graph library and I only have a few pages with graphs - the majority don’t require them).
cheers
Dave
Last Post!
greven
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex










