Loading scripts inside route on client-side navigation #2546
Replies: 3 comments 9 replies
-
Have you heard back from anyone on this @arthurdenner ? |
Beta Was this translation helpful? Give feedback.
-
Opinion from performance perspective: Having sub navigation trigger scripts reload/execution on a single page app isn't something we should expect. Let's take google analytics script as an example: On a normal html site, every navigation is a full page load. The google analytics script will be reloaded, and re-executed. This makes sense because the virtual JSDOM is blown away on every full page load. On a single page app site (like remix), this no longer makes sense. There is no need to reload and re-execute google analytics script. It is the same script and the same code. We are wasting CPU cycles for a script that is already in the virtual JSDOM. We just need to execute the google analytic supplied api, I would consider what is this external script you are trying to use in the remix app. Does it have an api implementation path? If it doesn't, can you contact the developers of this external script to supply one so that single page apps can perform well. If all else fails and that funky And if you are an agency, make sure your customer understands such performance impact and sign for it. |
Beta Was this translation helpful? Give feedback.
-
guys, really ? useEffect DOESN'T WORK. Tried to insert the facebook pixels of my checkout and... puff... nothing. |
Beta Was this translation helpful? Give feedback.
-
Hi! 👋🏽
I have a nested route that should load a specific script.
I've noticed that when navigating to that route client-side, the script was added to the DOM but not loaded and executed.
Only when reloading the page, it was loaded and executed. I was using an inline
script
tag.I'm not sure if this is the expected behaviour, hence I'm starting this discussion.
I've tried a few different approaches:
script
tagscript
tag added withuseEffect
ExternalScripts
fromremix-utils
(ref)script
tag added conditional in the root route (ref)From these, only the
useEffect
approach works as I expected (client-side navigation and page reload).I've put up a repository with a simple but reproducible example (ref).
Beta Was this translation helpful? Give feedback.
All reactions