Skip to content

Commit 8d55670

Browse files
authored
Dusting and cleaning of the web pages (#13160)
Fixes #13146 Also, fixes formatting and updates guidance around static websites.
1 parent a094154 commit 8d55670

File tree

5 files changed

+132
-86
lines changed

5 files changed

+132
-86
lines changed

src/content/platform-integration/web/building.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ application using Flutter.
1111

1212
Before you can build a web application with Flutter,
1313
make sure that you have the [Flutter SDK][] and a web browser installed.
14-
See the [Set up web development for Flutter][Setup-web] instructions
14+
Visit [Set up web development for Flutter][Setup-web] instructions
1515
for details.
1616

1717
## Set up a Flutter project
@@ -42,7 +42,7 @@ and run your Flutter app.
4242

4343
## Run your app
4444

45-
See the following sections to run your app.
45+
Check out the following sections to run your app.
4646

4747
### Run your app from the command line
4848

@@ -82,7 +82,7 @@ $ flutter run -d chrome --wasm
8282
```
8383

8484
Flutter web offers multiple build modes and renderers.
85-
For more information, see [Web renderers][].
85+
For more information, check out [Web renderers][].
8686

8787
### Disable hot reload in VS Code
8888

@@ -143,6 +143,7 @@ $ flutter build web
143143
```
144144

145145
### Build your app using WebAssembly
146+
146147
You can also pass the `--wasm` flag to build your app using WebAssembly:
147148

148149
```console
@@ -153,9 +154,9 @@ This populates a `build/web` directory
153154
with built files, including an `assets` directory,
154155
which need to be served together.
155156

156-
To learn more about how to deploy these assets to the web, see
157-
[Build and release a web app][].
158-
For answers to other common questions, see the [Web FAQ][].
157+
To learn more about how to deploy these assets to the web,
158+
visit [Build and release a web app][].
159+
For answers to other common questions, visit the [Web FAQ][].
159160

160161
## Debugging
161162

@@ -174,7 +175,7 @@ Use [Chrome DevTools][] for the following tasks:
174175
## Testing
175176

176177
Use [widget tests][Widget tests] or integration tests. To learn more about
177-
running integration tests in a browser, see the [Integration testing][] page.
178+
running integration tests in a browser, check out the [Integration testing][] page.
178179

179180
[Analyzing performance]: {{site.developers}}/web/tools/chrome-devtools/evaluate-performance
180181
[Build and release a web app]: /deployment/web

src/content/platform-integration/web/faq.md

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
22
title: Web FAQ
3-
description: Some gotchas and differences when writing or running web apps in Flutter.
3+
description: >-
4+
Some gotchas and differences when writing or running web apps in Flutter.
45
---
56

67
## Questions
78

89
### What scenarios are ideal for Flutter on the web?
910

10-
Not every web page makes sense in Flutter, but we think Flutter is particularly
11-
suited for app-centric experiences:
11+
Not every web page makes sense in Flutter,
12+
but we think Flutter is particularly suited for app-centric experiences:
1213

1314
* Progressive Web Apps
1415
* Single Page Apps
@@ -25,33 +26,40 @@ see [Web support for Flutter][].
2526

2627
### Search Engine Optimization (SEO)
2728

28-
In general, Flutter is geared towards dynamic application experiences. Flutter's
29-
web support is no exception. Flutter web prioritizes performance, fidelity, and
30-
consistency. This means application output does not align with what search
31-
engines need to properly index. For web content that is static or document-like,
32-
we recommend using HTML—just like we do on [flutter.dev]({{site.main-url}}),
33-
[dart.dev]({{site.dart-site}}), and [pub.dev]({{site.pub}}). You should also
34-
consider separating your primary application experience—created in Flutter—from
35-
your landing page, marketing content, and help content—created using
36-
search-engine optimized HTML.
37-
38-
That said, as mentioned in the [roadmap][], the Flutter team plans to
39-
investigate search engine indexability of Flutter web.
29+
In general, Flutter is geared towards dynamic application experiences.
30+
Flutter's web support is no exception.
31+
Flutter web prioritizes performance, fidelity, and consistency.
32+
This means application output doesn't align with what search
33+
engines need to properly index.
34+
35+
However, a community-released Dart package, [Jaspr][] _does_
36+
support static websites.
37+
In fact, the [Dart documentation][], [Flutter documentation][], and
38+
[Flutter marketing][] websites were migrated to using the Jaspr package.
39+
40+
To summarize, for web content that is static or document-like,
41+
we recommend _either_ using:
42+
43+
1. [Jaspr][], if you want to use Dart but want a more traditional
44+
DOM-based website. Also note that Jaspr makes SEO work in the
45+
same way a traditional website would.
46+
1. HTML—in this case, consider separating your primary application
47+
experience (created in Flutter), from your landing page,
48+
marketing content, and help content (created using
49+
search engine optimized HTML).
50+
51+
[Dart documentation]: {{site.dart-site}}
52+
[Flutter documentation]: /
53+
[Flutter marketing]: {{site.main-url}}
54+
[Jaspr]: https://jaspr.site/
4055

4156
### Does hot reload work with a web app?
4257

43-
Yes! For more information, check out
44-
[hot reload on the web][].
58+
Yes! For more information,
59+
check out [hot reload on the web][].
4560

4661
[hot reload on the web]: /platform-integration/web/building#hot-reload-web
4762

48-
Hot restart is a fast way of seeing your
49-
changes without having to relaunch your web app and wait for it
50-
to compile and load. This works similarly to
51-
the hot reload feature for Flutter mobile development.
52-
The difference is that hot reload remembers your state and hot
53-
restart doesn't.
54-
5563
### Which web browsers are supported by Flutter?
5664

5765
Flutter web apps can run on the following browsers:
@@ -61,8 +69,9 @@ Flutter web apps can run on the following browsers:
6169
* Edge (mobile & desktop)
6270
* Firefox (mobile & desktop)
6371

64-
During development, Chrome (on macOS, Windows, and Linux) and Edge (on Windows)
65-
are supported as the default browsers for debugging your app.
72+
During development, Chrome (on macOS, Windows, and Linux),
73+
and Edge (on Windows) are supported as the default browsers
74+
for debugging your app.
6675

6776
### Can I build, run, and deploy web apps in any of the IDEs?
6877

@@ -93,41 +102,57 @@ on [dart.dev]({{site.dart-site}}).
93102

94103
### Does Flutter web support concurrency?
95104

96-
Dart's concurrency support via [isolates][]
105+
Dart's concurrency support that uses [isolates][]
97106
is not currently supported in Flutter web.
98107

99108
Flutter web apps can potentially work around this
100109
by using [web workers][],
101-
although no such support is built in.
110+
although such support isn't built in.
102111

103112
### How do I deploy a web app?
104113

105114
See [Preparing a web app for release][].
106115

107116
### Does `Platform.is` work on the web?
108117

109-
Not currently.
118+
No. While you can technically import `dart:io` when compiling for the web,
119+
calling any `Platform.isXYZ` method throws an `UnsupportedError`.
120+
Furthermore, importing `dart:io` in a package
121+
(except through conditional imports) causes pub.dev
122+
to score the package as not supporting the web.
110123

111-
### Why doesn't my app update immediately after it's deployed?
124+
* If you are developing a Flutter app, consider using [`kIsWeb`][].
125+
* If you are developing a package
126+
(especially one without a Flutter dependency),
127+
consider using the [`os_detect`][] package.
112128

113-
You might need to configure the `Cache-Control` header returned by your web server.
114-
For example, if this header is set to 3600, then the browser
115-
and CDN will cache the asset for 1 hour, and your users might see an out-of-date
116-
version of your app up to 1 hour after you deploy a new version. For
117-
more information about caching on the web,
118-
check out [Prevent unnecessary network requests with the HTTP Cache][http-cache].
129+
[`kIsWeb`]: {{site.api}}/flutter/foundation/kIsWeb-constant.html
119130

120-
It is a good idea to be aware of this behavior to avoid an undesirable user experience.
131+
### Why doesn't my app update immediately after it's deployed?
132+
133+
You might need to configure the `Cache-Control` header
134+
returned by your web server.
135+
For example, if this header is set to 3600,
136+
then the browser and CDN will cache the asset for 1 hour,
137+
and your users might see an out-of-date
138+
version of your app up to 1 hour after you deploy a new version.
139+
For more information about caching on the web, check out
140+
[Prevent unnecessary network requests with the HTTP Cache][http-cache].
141+
142+
It's a good idea to be aware of this behavior to avoid an
143+
undesirable user experience.
121144
After you deploy your app, users might use a
122145
cached version of your app (cached by the browser or CDN)
123146
for the duration defined by your cache headers.
124-
This can lead to users using a version of your app that
125-
is incompatible with changes that have been deployed to backend services.
147+
This can lead to using a version of your app that
148+
is incompatible with changes that have been deployed
149+
to backend services.
126150

127151
### How do I clear the web cache after a deployment and force an app download?
128-
If you wish to defeat these cache headers after each deployment, a common
129-
technique is to append a build ID of some sort to the links of your static
130-
resources, or update the filenames themselves.
152+
153+
If you wish to defeat these cache headers after each deployment,
154+
a common technique is to append a build ID of some sort to the links
155+
of your static resources, or update the filenames themselves.
131156
For example, `logo.png` might become `logo.v123.png`.
132157

133158
```html
@@ -138,16 +163,17 @@ For example, `logo.png` might become `logo.v123.png`.
138163
<script src="flutter_bootstrap.v123.js" async></script>
139164
```
140165

141-
Flutter does not currently support appending build IDs to resources
166+
Flutter doesn't currently support appending build IDs to resources
142167
automatically.
143168

144169
### How do I configure my cache headers?
145170

146171
If you are using Firebase Hosting,
147-
the shared cache (CDN) is invalidated when you deploy a new version of your
148-
app. But you might choose to configure your cache headers as follows,
149-
so that the browser cache doesn't cache application scripts,
150-
but the shared cache does.
172+
the shared cache (CDN) is invalidated when you deploy a
173+
new version of your app.
174+
However, to make sure that the browser doesn't
175+
cache application scripts but the shared cache does,
176+
you can configure your cache headers as follows,
151177

152178
```json
153179
{
@@ -214,3 +240,4 @@ the `Cache-Control` header to a small value such as 0 or 60 seconds.
214240
[Web support for Flutter]: /platform-integration/web
215241
[web workers]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
216242
[workbox]: https://github.com/GoogleChrome/workbox
243+
[`os_detect`]: {{site.pub}}/packages/os_detect

src/content/platform-integration/web/index.md

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
---
22
title: Web support for Flutter
33
shortTitle: Web
4-
description: Details of how Flutter supports the creation of web experiences.
4+
description: >-
5+
Details of how Flutter supports the creation of web experiences.
56
---
67

78
Flutter delivers the same experiences on the web as on mobile.
89

9-
Building on the portability of Dart, the power of the web platform, the
10-
flexibility of the Flutter framework, and the performance of WebAssembly,
10+
Building on the portability of Dart, the power of the web platform,
11+
the flexibility of the Flutter framework, and the performance of WebAssembly,
1112
you can build apps for iOS, Android, and the browser from the same codebase.
1213
The web is just another device target for your app.
1314

@@ -21,23 +22,26 @@ a binary instruction format that enables fast apps on all major browsers.
2122
For a glimpse into the benefits of using WebAssembly,
2223
check out the following video.
2324

24-
<YouTubeEmbed id="lpnKWK-KEYs?start=1712" title="What's new in Flutter - WebAssembly"></YouTubeEmbed>
25+
<YouTubeEmbed id="lpnKWK-KEYs?start=1712"
26+
title="What's new in Flutter - WebAssembly"></YouTubeEmbed>
2527

2628
## How it works
2729

2830
Adding web support to Flutter involved implementing Flutter's
29-
core drawing layer on top of standard browser APIs, in addition
30-
to compiling Dart to JavaScript, instead of the ARM machine code that
31-
is used for mobile applications. Using a combination of DOM, Canvas,
32-
and WebAssembly, Flutter can provide a portable, high-quality,
31+
core drawing layer on top of standard browser APIs,
32+
in addition to compiling Dart to JavaScript,
33+
instead of the ARM machine code that
34+
is used for mobile applications.
35+
Using a combination of DOM, Canvas, and WebAssembly,
36+
Flutter can provide a portable, high-quality,
3337
and performant user experience across modern browsers.
3438
We implemented the core drawing layer completely in Dart
3539
and used Dart's optimized JavaScript compiler to compile the
36-
Flutter core and framework along with your application
37-
into a single, minified source file that can be deployed to
38-
any web server.
40+
Flutter core and framework along with your application into a single,
41+
minified source file that can be deployed to any web server.
3942

40-
<img src="/assets/images/docs/arch-overview/web-framework-diagram.png" alt="Flutter architecture for web" >
43+
<img src="/assets/images/docs/arch-overview/web-framework-diagram.png"
44+
alt="Flutter architecture for web" >
4145

4246
## What types of apps can I build?
4347

@@ -61,25 +65,39 @@ rather than the app-centric services that a UI framework like Flutter
6165
can deliver. However, you _can_ use Flutter to embed interactive
6266
experiences into these websites.
6367

68+
However, if you want to use Dart and wish to implement a traditional
69+
DOM-based website, a community-released Dart package,
70+
[Jaspr][], supports static websites; in fact,
71+
the [Dart documentation][] and [Flutter documentation][]
72+
and [marketing][] websites were migrated to use the Jaspr package.
73+
Note that Jaspr uses Dart (but not Flutter), and makes SEO work in the same
74+
way a traditional website would.
75+
76+
[Dart documentation]: {{site.dart-site}}
77+
[Flutter documentation]: {{site.main-url}}
78+
[Jaspr]: https://jaspr.site/
79+
[marketing]: {{site.main-url}}
80+
6481
## Get started
6582

6683
The following resources can help you get started:
6784

6885
* To add web support to an existing app, or to create a
69-
new app that includes web support, see
70-
[Building a web application with Flutter][].
71-
* To configure web development server settings in a centralized file, see [Set up a web development configuration file][].
72-
* To learn about Flutter's different web renderers (CanvasKit and Skwasm), see
73-
[Web renderers][].
86+
new app that includes web support,
87+
visit [Building a web application with Flutter][].
88+
* To configure web development server settings in a centralized file,
89+
check out [Set up a web development configuration file][].
90+
* To learn about Flutter's different web renderers (CanvasKit and Skwasm),
91+
check out [Web renderers][].
7492
* To learn how to create a responsive Flutter
75-
app, see [Creating responsive apps][].
76-
* To view commonly asked questions and answers, see the
77-
[web FAQ][].
78-
* To see code examples,
93+
app, check out [Creating responsive apps][].
94+
* To view commonly asked questions and answers,
95+
visit the [web FAQ][].
96+
* For code examples,
7997
check out the [web samples for Flutter][].
80-
* To see a Flutter web app demo, check out the [Wonderous app][].
81-
* To learn about deploying a web app, see
82-
[Preparing an app for web release][].
98+
* For a Flutter web app demo, check out the [Wonderous app][].
99+
* To learn about deploying a web app,
100+
visit [Preparing an app for web release][].
83101
* [File an issue][] on the main Flutter repo.
84102
* You can chat and ask web-related questions on the
85103
**#help** channel on [Discord][].

src/content/platform-integration/web/initialization.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ The `config` argument is an object that can have the following optional fields:
137137
A boolean flag to force the Skia WebAssembly (skwasm) renderer
138138
to run in **single-threaded mode**. This is useful if:
139139

140-
- Your environment does not support multi-threaded WASM (for example,
140+
* Your environment doesn't support multi-threaded WASM. For example,
141141
`SharedArrayBuffer` is not available or required security
142-
headers are missing).
143-
- You want maximum browser compatibility.
144-
- Use `false` (default) to allow multi-threaded rendering when
142+
headers are missing.
143+
* You want maximum browser compatibility.
144+
* Use `false` (default) to allow multi-threaded rendering when
145145
supported, which improves performance.
146146

147147
## Example usage
@@ -159,7 +159,7 @@ _flutter.loader.load({
159159

160160
The following example shows a custom `flutter_bootstrap.js` that allows
161161
the user to select a renderer by providing a `renderer` query parameter,
162-
e.g. `?renderer=skwasm`, in the URL of their website:
162+
such as `?renderer=skwasm`, in the URL of their website:
163163

164164
```js
165165
{% raw %}{{flutter_js}}{% endraw %}
@@ -244,7 +244,7 @@ Warning: In index.html:37: Local variable for "serviceWorkerVersion" is deprecat
244244
Use "{{flutter_service_worker_version}}" template token instead.
245245
```
246246

247-
You can fix this by deleting the following line in the `web/index.html` file:
247+
You can fix this by deleting the following line from the `web/index.html` file:
248248

249249
```html title="web/index.html"
250250
var serviceWorkerVersion = null;

0 commit comments

Comments
 (0)