|
1 | | -Placeholder content |
| 1 | +A type of [block](api/core/defer) that can be used to defer load the JavaScript for components, directives and pipes used inside a component template. |
| 2 | + |
| 3 | +@syntax |
| 4 | + |
| 5 | +```html |
| 6 | +@defer ( on <trigger>; when <condition>; prefetch on <trigger>; prefetch when <condition> ) { |
| 7 | + <!-- deferred template fragment --> |
| 8 | + <calendar-cmp /> |
| 9 | +} @placeholder ( minimum? <duration> ) { |
| 10 | + <!-- placeholder template fragment --> |
| 11 | + <p>Placeholder</p> |
| 12 | +} @loading ( minimum? <duration>; after? <duration> ) { |
| 13 | + <!-- loading template fragment --> |
| 14 | + <img alt="loading image" src="loading.gif" /> |
| 15 | +} @error { |
| 16 | + <!-- error template fragment --> |
| 17 | + <p>An loading error occured</p> |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +@description |
| 22 | + |
| 23 | +<h3>Blocks</h3> |
| 24 | + |
| 25 | +Supported sections of a defer block. Note: only the @defer block template fragment is deferred loaded. The remaining optional blocks are eagerly loaded. |
| 26 | + |
| 27 | +| block | Description | |
| 28 | +| ----------- | ----------- | |
| 29 | +| `@defer` | The defer loaded block of content | |
| 30 | +| `@placeholder` | Content shown prior to defer loading (Optional)| |
| 31 | +| `@loading` | Content shown during defer loading (Optional) | |
| 32 | +| `@error` | Content shown when defer loading errors occur (Optional) | |
| 33 | + |
| 34 | +<h3>Triggers</h3> |
| 35 | + |
| 36 | +Triggers provide conditions for when defer loading occurs. Some allow a template reference variable as an optional parameter. Separate multiple triggers with a semicolon. |
| 37 | + |
| 38 | +| trigger | Triggers... | |
| 39 | +| ----------- | ----------- | |
| 40 | +| `on idle` | when the browser reports idle state (default) | |
| 41 | +| `on viewport(<elementRef>?)` | when the element enters the viewport | |
| 42 | +| `on interaction(<elementRef>?)` | when clicked, touched, or focused | |
| 43 | +| `on hover(<elementRef>?)` | when element has been hovered | |
| 44 | +| `on immediate` | when the page finishes rendering | |
| 45 | +| `on timer(<duration>)` | after a specific timeout | |
| 46 | +| `when <condition>` | on a custom condition | |
| 47 | + |
| 48 | +<h2>Prefetch</h2> |
| 49 | + |
| 50 | +Triggers prefetching of the defer block used in the `@defer` parameters. Separate multiple prefetch triggers with a semicolon. |
| 51 | + |
| 52 | +```html |
| 53 | +@defer (prefetch on <trigger>; prefetch when <condition>) { |
| 54 | + <!-- deferred template fragment --> |
| 55 | +} |
| 56 | +``` |
| 57 | + |
0 commit comments