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

Document [data-turbo-track="dynamic"] #168

Merged
merged 1 commit into from
Jun 21, 2024

Commits on Feb 20, 2024

  1. Document [data-turbo-track="dynamic"]

    Follow-up to [hotwired/turbo#1140][]
    
    Removing Assets When They Change
    ---
    
    As we saw above, Turbo Drive merges the contents of the `<head>`
    elements. When a page depends on external assets like CSS stylesheets
    that other pages do not, it can be useful to remove them when navigating
    away from the page.
    
    Rendering a `<link>` or `<style>` element with
    `[data-turbo-track="dynamic"]` instructs Turbo Drive to dynamically
    remove the element when it is absent from a navigation's response, and
    can serve a complementary role to the `[data-turbo-track="reload"]`
    attribute to avoid triggering a full page reload when deploying changes
    that only affect styles.
    
    ```html
    <head>
      <!-- … -->
      <link rel="stylesheet" href="/page-specific-styles-258e88d.css" data-turbo-track="dynamic">
      <style data-turbo-track="dynamic">
        .page-specific-styles { /* … */ }
      </style>
    </head>
    ```
    
    Note that rendering `<script>` elements with
    `[data-turbo-track="dynamic"]` might unintended side-effects. When
    `<script>` disconnected from the document, the JavaScript context
    doesn't change, nor is the element's already evaluated JavaScript code
    unloaded or changed in any way.
    
    [hotwired/turbo#1140]: hotwired/turbo#1140
    seanpdoyle committed Feb 20, 2024
    Configuration menu
    Copy the full SHA
    18d80d0 View commit details
    Browse the repository at this point in the history