You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49-19Lines changed: 49 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,9 @@
6
6
7
7
Django Suspense is small package to easily display a fallback in templates until children have finished loading.
8
8
9
+
9
10
## Quick start
11
+
10
12
### 1. Install package:
11
13
To get started, install the package from [pypi](https://pypi.org/project/django-suspense/):
12
14
```bash
@@ -42,36 +44,24 @@ TEMPLATES = [
42
44
```
43
45
If you choose not use it as a built-in, you will need to add `{% load suspense %}` to the top of your template whenever you want to use suspense.
44
46
45
-
### 2. Add `suspense` to `urls.py`:
46
-
This is necessary because some parts of the pages will be loaded asynchronously (via http).
47
-
```python
48
-
from django.urls import include, path
49
47
50
-
51
-
urlpatterns = [
52
-
...,
53
-
path('/_suspense/', include('suspense.urls'))
54
-
]
55
-
```
56
-
57
-
### 3. Create view with slow lazy load object:
48
+
### 2. Create view with slow lazy load object:
58
49
Because django executes database queries lazily, they may sometimes not work as expected. Let's try to create a very slow but lazy object and write a view function:
Let's now add the output of the received data to the template. At this point, we still haven't made a database query, so we can easily and quickly show the template right away.
76
66
```html
77
67
{% load suspense %}
@@ -92,7 +82,47 @@ Let's now add the output of the received data to the template. At this point, we
92
82
```
93
83
Once obj is ready for use, we will show it. But until it is ready, fallback works. While we are waiting for the data to be displayed, a request is made on the client side.
94
84
95
-
### 5. Hooray! Everything is ready to use it.
85
+
### 4. Hooray! Everything is ready to use it.
86
+
87
+
88
+
## Troubleshooting
89
+
90
+
### Safari delay in rendering
91
+
92
+
On Safari if your webpage is very light/simple, you may experience a delay in rendering.
93
+
94
+
Ex: the page renders only after some django-suspense or all content is downloaded.
95
+
96
+
WebKit has an issue with streaming responses requiring a certain amount of visible content before to actually start rendering.
97
+
98
+
See [webkit issue #252413](https://bugs.webkit.org/show_bug.cgi?id=252413)
99
+
100
+
If you are experiencing this issue, you can use the additional `{% webkit_extra_invisible_bytes %}` template tag to add a few extra invisible bytes in Safari.
101
+
102
+
```html
103
+
{% load suspense %}
104
+
105
+
{% webkit_extra_invisible_bytes %}
106
+
```
107
+
108
+
By default the `webkit_extra_invisible_bytes` adds 200 bytes but you can specify a different amount:
109
+
110
+
```html
111
+
{% webkit_extra_invisible_bytes 300 %}
112
+
```
113
+
114
+
### Content Security Policy (CSP) nonce error because of `strict-dynamic`
115
+
116
+
If you are using a Content Security Policy (CSP) with `nonce` and [`strict-dynamic`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src#strict-dynamic), you may need to add the `nonce` attribute to the script tag.
117
+
118
+
You can override the `suspense/replacer.html` template and add the `nonce` attribute to the script tag.
119
+
120
+
With [django-csp](https://django-csp.readthedocs.io/en/latest/nonce.html#middleware):
0 commit comments