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

Using defer on frontend for JS Bundle, Libs and custom scripts | Hot-controls and Turbo router #5833

Open
flyingbaba opened this issue Feb 5, 2025 · 1 comment

Comments

@flyingbaba
Copy link

flyingbaba commented Feb 5, 2025

It was mentioned in docs that it is good practise to put scripts in the head of the page with defer attribute. That gives a very good performance boost since the loading of the main scripts is not blocking the rendering of the HTML on a first load.

We are using hot-controls (turbo router) and have scripts inside pages and partials like this:

[resources]
js[] = “path/to/controls.js”

These scripts are loaded prior framework, causing errors then first loaded. (next pjax visits are fine, since the oc. is initialized already)

Need a way to defer load them something like: {% scripts defer %} or {% put scripts defer %}?

Forum link to issue: https://talk.octobercms.com/t/using-defer-for-js-bundle-experiment-performance/3234/3

@daftspunk
Copy link
Member

daftspunk commented Feb 16, 2025

Thanks for reporting this. We'll need to improve the Resources component to introduce a deferred pipeline.

Some possible options to consider:

js[] = "defer:path/to/controls.js"
js[] = "path/to/controls.js?defer=true"
js[] = "path/to/controls.js#defer"
jsDefer[] = "path/to/controls.js"

Also, I noticed that the js[] declaration doesn't support fully qualified URLs...

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

No branches or pull requests

2 participants