Skip to content

Commit

Permalink
Merge pull request #130 from hotwired/jh/turbo-temporary
Browse files Browse the repository at this point in the history
Document [data-turbo-temporary] as the replacement of [data-turbo-cache=false]
  • Loading branch information
dhh authored Feb 15, 2023
2 parents c1acc01 + 476eca4 commit eebefee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion _source/handbook/06_building.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ document.addEventListener("turbo:before-cache", function() {
})
```

Annotate elements with `data-turbo-cache="false"` if you do not want Turbo to cache them. This is helpful for temporary elements, like flash notices.
Certain page elements are inherently _temporary_, like flash messages or alerts. If they’re cached with the document they’ll be redisplayed when it’s restored, which is rarely desirable. You can annotate such elements with `data-turbo-temporary` to have Turbo Drive automatically remove them from the page before it’s cached.

```html
<body>
<div class="flash" data-turbo-temporary>
Your cart was updated!
</div>
...
</body>
```

### Detecting When a Preview is Visible

Expand Down
2 changes: 1 addition & 1 deletion _source/reference/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The following data attributes can be applied to elements to customize Turbo's be
* `data-turbo-frame` identifies the Turbo Frame to navigate. Refer to the [Frames documentation](/reference/frames) for further details.
* `data-turbo-action` customizes the [Visit](/handbook/drive#page-navigation-basics) action. Valid values are `replace` or `advance`. Can also be used with Turbo Frames to [promote frame navigations to page visits](/handbook/frames#promoting-a-frame-navigation-to-a-page-visit).
* `data-turbo-permanent` [persists the element between page loads](/handbook/building#persisting-elements-across-page-loads). The element must have a unique `id` attribute.
* `data-turbo-cache="false"` removes the element before the document is cached, preventing it from reappearing on restoration Visits.
* `data-turbo-temporary` removes the element before the document is cached, preventing it from reappearing when restored.
* `data-turbo-eval="false"` prevents inline `script` elements from being re-evaluated on Visits.
* `data-turbo-method` changes the link request type from the default `GET`. Ideally, non-`GET` requests should be triggered with forms, but `data-turbo-method` might be useful where a form is not possible.
* `data-turbo-stream` specifies that a link or form can accept a Turbo Streams response. Turbo [automatically requests stream responses](/handbook/streams#streaming-from-http-responses) for form submissions with non-`GET` methods; `data-turbo-stream` allows Turbo Streams to be used with `GET` requests as well.
Expand Down

0 comments on commit eebefee

Please sign in to comment.