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

Remove unused stylesheets when navigating #1128

Merged
merged 1 commit into from Jan 15, 2024
Merged

Commits on Jan 15, 2024

  1. Remove unused stylesheets when navigating

    When navigating to another page, Turbo merges the `<head>` contents from
    the current and new pages, which results in a `<head>` containing the
    superset of both.
    
    For certain items, like scripts, this makes sense. We have no way to
    remove a running script. But that's not the case for styles: styles can
    be unloaded easily, and for the page to display properly, we need to do
    so. Otherwise styles kept in scope from a previous page could cause a
    page to render incorrectly.
    
    The common way to avoid this has been to use `data-turbo-track="reload"`
    to force a reload if styles change. This works, but it's a bit
    heavy-handed, causing full page reloads that could have been avoided.
    
    There are a couple of common cases where updating styles on the fly
    would be useful:
    
    - Deploying a CSS change. Clients should be able to pick up the change
      without having to reload.
    
    - Allowing pages to include their own specific styles, rather than
      bundle them all together for the whole site. This can reduce the size
      of the loaded CSS, and make it easier to avoid style conflicts.
    kevinmcconnell committed Jan 15, 2024
    Configuration menu
    Copy the full SHA
    cafbd50 View commit details
    Browse the repository at this point in the history