Document [data-turbo-track="dynamic"]
#168
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 dynamicallyremove 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.
Note that rendering
<script>
elements with[data-turbo-track="dynamic"]
might unintended side-effects. When<script>
disconnected from the document, the JavaScript contextdoesn't change, nor is the element's already evaluated JavaScript code
unloaded or changed in any way.