Skip to content

Commit ca7f30d

Browse files
author
Steve Orvell
authored
Adds browser support info (#117)
Adds browser support info to Build > Requirements
1 parent 606ff2c commit ca7f30d

File tree

7 files changed

+96
-34
lines changed

7 files changed

+96
-34
lines changed

packages/lit-dev-content/.eleventy.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,10 @@ ${content}
266266
).filter(
267267
// TODO(aomarks) This is brittle, we need a way to annotate inside an md
268268
// file that a page shouldn't be generated.
269-
(file) => !file.includes('why-lit') && !file.includes('getting-started')
269+
(file) =>
270+
!file.includes('why-lit') &&
271+
!file.includes('getting-started') &&
272+
!file.includes('browser-support')
270273
);
271274
await Promise.all(emptyDocsIndexFiles.map((path) => fs.unlink(path)));
272275

packages/lit-dev-content/site/guide/getting-started.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,7 @@ If you already have a dev server that works with your build system, it should wo
323323
324324
### Supporting older browsers
325325
326-
To support older browsers that don't support ES6 and the web components specifications, you'll need to take a few extra steps to produce code that will run on the older browsers.
327-
328-
See [Build for production](build) for more information.
326+
For older browsers like Internet Explorer 11 that don't support ES2020 and web components natively, see [Tools and Workflows](/guide/tools/overview) for information about setting up Lit to work for testing, development, building, and publishing.
329327
330328
### Next steps
331329

packages/lit-dev-content/site/guide/platform-support/index.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/lit-dev-content/site/guide/platform-support/overview.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

packages/lit-dev-content/site/guide/tools/development.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ There are many development servers that can deal with module specifiers. If you
3030

3131
If you need a dev server, we recommend [Web Dev Server](https://modern-web.dev/docs/dev-server/overview/).
3232

33-
### Web Dev Server
33+
### Web Dev Server { #web-dev-server }
3434

3535
[Web Dev Server](https://modern-web.dev/docs/dev-server/overview/) is an open-source dev server that enables a build-free development process.
3636

packages/lit-dev-content/site/guide/tools/requirements.md

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ Webpack automatically handles bare module specifiers; for Rollup, you'll need a
3131

3232
**Why bare module specifiers?** Bare module specifiers let you import modules without knowing exactly where the package manager has installed them. A standards proposal called [Import maps](https://github.com/WICG/import-maps) is [starting to ship](https://chromestatus.com/feature/5315286962012160), which will let let browsers support bare module specifiers. In the meantime, bare import specifiers can easily be transformed as a build step. There are also some polyfills and module loaders that support import maps.
3333

34+
### Modern browser breakdown
35+
36+
All modern browsers update automatically and users are highly likely to have a recent version. The following table lists the minimum version of each major browser that natively supports ES2020 and web components, the key features on which Lit relies.
37+
38+
| Browser | Supports ES2020 & web components |
39+
|:--------|:--------------------------------:|
40+
| Chrome | >=80 |
41+
| Safari | >=13 |
42+
| Firefox | >=72 |
43+
| Edge | >=80 |
44+
3445
## Requirements for legacy browsers {#building-for-legacy-browsers}
3546

3647
Supporting older browsers (specifically Internet Explorer 11, but also older versions of evergreen browsers), requires a number of extra steps:
@@ -39,6 +50,19 @@ Supporting older browsers (specifically Internet Explorer 11, but also older ver
3950
* Transforming ES modules to another module system.
4051
* Loading polyfills.
4152

53+
### Legacy browser breakdown
54+
55+
The following table lists supported browser versions that require transpiling Javascript and loading polyfills:
56+
57+
| Browser | Transpile JS | Transpile JS & load polyfills |
58+
|:------------------|:------------:|:-----------------------------:|
59+
| Chrome | 67-79 | <67 |
60+
| Safari | 10-12 | <10 |
61+
| Firefox | 63-71 | <63 |
62+
| Edge | 79 | |
63+
| Edge "classic" | | <=18 |
64+
| Internet Explorer | | 11 |
65+
4266
### Transpiling to ES5 {#transpiling-to-es5}
4367

4468
Rollup, webpack and other build tools have plugins to support transpiling modern JavaScript for older browsers. [Babel](https://babeljs.io/) is the most commonly used transpiler.
@@ -79,7 +103,7 @@ The IIFE format works fine if all of your code can be bundled into a single file
79103

80104
## Polyfills {#polyfills}
81105

82-
Using Lit on older browsers will require loading polyfills for standard JavaScript features like Promises and async/await, the Web Components polyfills, as well as a `polyfill-support` script provided in the Lit package for interfacing Lit with the Web Components polyfills.
106+
Using Lit on older browsers will require loading polyfills for standard JavaScript features like Promises and async/await, the web components polyfills, as well as a `polyfill-support` script provided in the Lit package for interfacing Lit with the Web Components polyfills.
83107

84108
These are the recommended polyfills:
85109

@@ -91,12 +115,71 @@ These are the recommended polyfills:
91115
* [`requirejs`](https://www.npmjs.com/package/requirejs) - AMD module loader
92116
* Polyfills for Web Components:
93117
* [`@webcomponents/webcomponentsjs`](https://www.npmjs.com/package/@webcomponents/webcomponentsjs) - Polyfills for custom elements, shadow DOM, template, and some newer DOM APIs
94-
* `lit/platform-support.js` - A file that ships in the `lit` package that must be loaded when using `webcomponentsjs`
118+
* `lit/polyfill-support.js` - A file that ships in the `lit` package that must be loaded when using `webcomponentsjs`
119+
120+
Note that you may need other polyfills depending on the features your application uses.
121+
122+
### Loading polyfills
95123

96-
<div class="alert alert-info">
124+
The Javascript polyfills should be bundled separately from the application bundle, and loaded before the web components polyfills, since those polyfills rely on modern JS like `Promise`. Putting it all together, the page should load code as follows:
97125

98-
Note that the Javascript polyfills should be bundled separately from the application bundle, and loaded before the Web Components polyfills, since those polyfills rely on modern JS like `Promise`.
126+
```html
127+
<script src="path/to/js/polyfills/you/need.js"></script>
128+
<script src="node_modules/lit/polyfill-support.js"></script>
129+
<script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
130+
<!-- Load application code here -->
131+
```
99132

100-
</div>
133+
### Web components polyfills
101134

102-
Note that you may need other polyfills depending on the features your application uses.
135+
For detailed information about loading and configuring the web components polyfills, see the [webcomponentsjs documentation](https://github.com/webcomponents/polyfills/tree/master/packages/webcomponentsjs). The following is a summary of some of the key points.
136+
137+
#### Loading options
138+
139+
There are two main ways to load the web components polyfills:
140+
141+
- `webcomponents-bundle.js` includes all of the polyfills necessary to run on any of the supported browsers. Because all browsers receive all polyfills, this results in extra bytes being sent to browsers that support one or more feature.
142+
- `webcomponents-loader.js` performs client-side feature-detection and loads just the required polyfills. This requires an extra round-trip to the server, but saves bandwidth for browsers that support one or more features.
143+
144+
#### Loading the ES5 adapter
145+
146+
It's best to serve a modern build to modern browsers to avoid sending the extra code needed for older browsers. However, it can be convenient to serve just a single set of files. If you do this, there is one extra required step. In order for ES5 transpiled code to work with native web components and specifically custom elements, a small adapter is needed. For a detailed explanation, see the [webcomponentsjs documentation](https://github.com/webcomponents/polyfills/tree/master/packages/webcomponentsjs#custom-elements-es5-adapterjs).
147+
148+
Load the `custom-elements-es5-adapter.js` after any Babel polyfills and before web components, like this:
149+
150+
```html
151+
<script src="path/to/js/polyfills/you/need.js"></script>
152+
<script src="node_modules/@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js"></script>
153+
<script src="node_modules/lit/polyfill-support.js"></script>
154+
<script src="node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
155+
<!-- Load application code here -->
156+
```
157+
158+
#### Setting web components polyfill options
159+
160+
By default, the individual polyfill for a given feature is disabled on browsers that natively support that feature.
161+
For testing purposes, you can force the polyfills on for browsers that have native support.
162+
163+
While the web components polyfills strive to match the spec, there are some infidelities particularly around styling (see [ShadyCSS limitations](https://github.com/webcomponents/polyfills/tree/master/packages/shadycss#limitations)). We recommend ensuring you test with polyfills both on and off, either on the browsers that need them, or by forcing them on. You can force the polyfills on by adding a JavaScript snippet before you import the polyfills:
164+
165+
```html
166+
<script>
167+
// Force all polyfills on
168+
if (window.customElements) window.customElements.forcePolyfill = true;
169+
ShadyDOM = { force: true };
170+
ShadyCSS = { shimcssproperties: true};
171+
</script>
172+
<script src="./node_modules/@webcomponents/webcomponentsjs/webcomponents-loader.js"></script>
173+
```
174+
175+
Or, you if you use the `webcomponents-bundle.js` file, you can force the polyfills on by adding query parameters to the app's URL:
176+
177+
`https://www.example.com/my-application/view1?wc-ce&wc-shadydom&wc-shimcssproperties`
178+
179+
The following table lists the JavaScript snippets and query parameters for each polyfill.
180+
181+
| Polyfill | Javascript | Query parameter |
182+
|:------------|:------------------------------------|:-------------------------|
183+
| Custom Elements | `if (window.customElements) window.customElements.forcePolyfill = true;` | `wc-ce` |
184+
| Shadow DOM | `ShadyDOM = { force: true };` | `wc-shadydom` |
185+
| CSS custom properties | `ShadyCSS = { shimcssproperties: true};` | `wc-shimcssproperties` |

packages/lit-dev-content/site/guide/tools/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The test environment you use must have support for using modern Javascript, incl
3232

3333
To test on older browsers, your test environment will need to load some polyfills, including the [web components polyfills](https://github.com/webcomponents/polyfills/tree/master/packages/webcomponentsjs) and Lit's `polyfill-support` module. See the [Browser Support](../browser-support) documentation for more details.
3434

35-
## Using Web Test Runner
35+
## Using Web Test Runner { #web-test-runner }
3636

3737
We recommend using [Web Test Runner](https://modern-web.dev/docs/test-runner/overview/) since it is specifically designed to test modern web libraries like Lit using modern web features like custom elements and shadow DOM. See the [Getting Started](https://modern-web.dev/guides/test-runner/getting-started) documentation for Web Test Runner.
3838

0 commit comments

Comments
 (0)