back

by padolsey·14y ago·view on hn ↗
For example, setting up event delegation on enhanced elements is best done in the HEAD before the elements load. If you setup all your user-event listeners in the bottom of BODY then your users will have a short time when they'll be interacting with elements which A) will do the non-enhanced behaviour B) do nothing whatsoever. Neither A nor B is ideal.
1 comments
Nah, have a small inline script that records events and replays them to your full script when it loads.

Or, if something only works with js, don't show it until the scripts have loaded, but let plain content load & render in the meantime.

Yeh, both viable solutions. Tbh, I can't think of any other reason to have JS in the HEAD.
Google Analytics is generally the only JS I put in the head. If some code is absolutely required for the page to work though then it may make sense to put it ahead of the content.