-
Notifications
You must be signed in to change notification settings - Fork 434
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
[proposal] Removing unused stylesheets and scripts in head #1082
Comments
Removing unused stylesheets is a great idea because the browser automatically updates the associated styles without needing a full page reload. Removing JS is trickier. The JS state is not going to change after removing the outdated But just being able to pick up new styles without a full page reload is a nice feature, will accept a PR implementing that 👍 |
Happy to send a PR, but I couldn't get it working with caching enabled. When I called Would appreciate some pointers there. |
draft PR at #1088 |
Here's a solution that uses much less code, based on a head refactor I made a PR on. #832 The issue remains with the cache you mentioned (#1082 (comment)) is still at play here. I'm familiarizing myself with the cache mechanism now to see what can be done to fix that. The code can be further optimized once the cached snapshot issue is figured out as the
|
looks like we have a solution just merged from #1128. Not yet tried it though. |
Right, #1128 closes this. |
So I understand that any new stylesheets and scripts in the head of the new page will be appended to the current head. Which is great, but what's not so great, is that these appended assets stick around even when not needed. So if I have some page specific CSS or JS, they will persist way beyond the page they are used.
I also understand that the recommended solution to this is to include these page specific assets in the body, instead of the head.
This is however, not ideal. Particularly when it comes to styles, as styles are render blocking assets, resulting in a flash of unstyled content when loading a new page that includes CSS within the body.
I've been playing around and have found what I believe to be a better solution that allows me to include assets in the head, but cleans up any unused or page specific assets.
After Turbo merges the head, the stylesheets and scripts within the new and current snapshots are compared. Any current asset not found in the new snapshot is removed from the head. Something like this...
This works nicely in my [limited] testing, but not so great if caching is enabled - I need to dig deeper into that. But before I do so, I wanted to get some feedback on this idea, and ensure that I've not overlooked anything.
Thanks, and any and all feedback is appreciated.
The text was updated successfully, but these errors were encountered: