Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions examples/with-ie11/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# With Internet Explorer 11 example

## How to use

Download the example [or clone the repo](https://github.com/zeit/next.js):

```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/master | tar -xz --strip=2 next.js-master/examples/with-ie11
cd with-ie11
```

Install it and run:

```bash
npm install
npm run dev
```

Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download))

```bash
now
```

## The idea behind the example

This example shows how to add a `Promise` polyfill to Next.js. Which allows you to use Next.js on Internet Explorer 11.
17 changes: 17 additions & 0 deletions examples/with-ie11/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "with-ie11",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"isomorphic-fetch": "^2.2.1",
"next": "^2.0.0-beta",
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"author": "",
"license": "ISC"
}
28 changes: 28 additions & 0 deletions examples/with-ie11/pages/_document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Document, { Head, Main, NextScript } from 'next/document'

export default class MyDocument extends Document {
static async getInitialProps (context) {
const props = await super.getInitialProps(context)

const userAgent = context.req.headers['user-agent']
const isIE11 = !!userAgent.match(/Trident\/7\./)

return { ...props, isIE11 }
}

render () {
return (
<html>
<Head>
{this.props.isIE11 ? (
<script src='https://cdnjs.cloudflare.com/ajax/libs/es6-promise/4.0.5/es6-promise.auto.js' />
) : null}
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
)
}
}
22 changes: 22 additions & 0 deletions examples/with-ie11/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import React from 'react'
import Link from 'next/link'
import 'isomorphic-fetch'

export default class MyPage extends React.Component {
static async getInitialProps () {
// eslint-disable-next-line no-undef
const res = await fetch('https://api.github.com/repos/zeit/next.js')
const json = await res.json()
return { stars: json.stargazers_count }
}

render () {
return (
<div>
<p>Next.js has {this.props.stars} ⭐️</p>
<Link prefetch href='/preact'><a>How about preact?</a></Link>
</div>
)
}
}
22 changes: 22 additions & 0 deletions examples/with-ie11/pages/preact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

import React from 'react'
import Link from 'next/link'
import 'isomorphic-fetch'

export default class MyPage extends React.Component {
static async getInitialProps () {
// eslint-disable-next-line no-undef
const res = await fetch('https://api.github.com/repos/developit/preact')
const json = await res.json()
return { stars: json.stargazers_count }
}

render () {
return (
<div>
<p>Preact has {this.props.stars} ⭐️</p>
<Link prefetch href='/'><a>I bet next has more stars (?)</a></Link>
</div>
)
}
}