Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] script loading before DOM generation. #17

Closed
laaledesiempre opened this issue Feb 8, 2024 · 3 comments
Closed

[BUG] script loading before DOM generation. #17

laaledesiempre opened this issue Feb 8, 2024 · 3 comments

Comments

@laaledesiempre
Copy link
Contributor

This is going to be solved on the next update. made me lose some time but:
scripts have to be put at the end of the body, not the header, if you put it on the header then it will load BEFORE the dom and fuctions depending on dom will fail and make crashes, and when you are using modals you have to set them into the javascript to close/open them so this made it crash.

@Dpeta
Copy link
Owner

Dpeta commented Feb 8, 2024

That's not really a bug, pco currently already accounts for that and only runs code that depends on the page being loaded when it actually is, that's what the init function is for. Though maybe that's an outdated solution if the defer attribute exists...

@laaledesiempre
Copy link
Contributor Author

yeah, there is this "dom loaded" event listener but now you usually put script just on the body bc. you dont have to load things before dom is already there. usually, this just makes the browser load the javascript before. what also makes the page a little bit slower, and make run time races error with "new" javascript code (as <dialog> modals i'd been implementing). javascript life cycle paradigm is something that changed a lot this years since React functional components became a default, and SSR gained more relevance for SEO reasons.
the scripts in head are for libraries like jquery or cdns. and that kind of stuff that you want to load before dom, but things that interact on the dom. should be on body. (as a convention, at the end of the day, you can put it wherever you want).

@laaledesiempre
Copy link
Contributor Author

solved by using defer on the tag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants