preload experiment

main
Mike Fix 6 years ago committed by Michael Fix
parent 4321c28609
commit ec101f0ad2

@ -1,10 +1,10 @@
import React from 'react'
import Head from 'next/head'
import ReactCrop, { makeAspectCrop } from 'react-image-crop'
import RandomImage, { downloadThumbnailImage } from './RandomImage'
import PhotoCredit from './PhotoCredit'
import Input from './Input'
import { Link } from './Meta'
import { fileToDataURL } from '../lib/util'
const getCroppedImg = (imageDataURL, pixelCrop) => {
@ -309,9 +309,7 @@ export default class ImagePicker extends React.Component {
return (
<div className="image-picker-container">
<Head>
<link rel="stylesheet" href="/static/react-crop.css" />
</Head>
<Link href="/static/react-crop.css" />
{content}
<style jsx>
{`

@ -6,9 +6,17 @@ import Font from './style/Font'
import Typography from './style/Typography'
const LOCAL_STYLESHEETS = ['one-light', 'one-dark', 'verminal', 'night-owl', 'nord']
const CDN_STYLESHEETS = THEMES.filter(t => LOCAL_STYLESHEETS.indexOf(t.id) < 0)
export function Link({ key, href }) {
return (
<Head>
<link rel="preload" as="style" href={href} />
<link key={key} rel="stylesheet" href={href} />
</Head>
)
}
export const StylesheetLink = ({ theme }) => {
let href
if (LOCAL_STYLESHEETS.indexOf(theme) > -1) {
@ -19,67 +27,49 @@ export const StylesheetLink = ({ theme }) => {
(themeDef.link || themeDef.id)}.min.css`
}
return (
<Head>
<link key={href} rel="stylesheet" href={href} />
</Head>
)
return <Link href={href} />
}
export const CodeMirrorLink = () => (
<Head>
<link
key="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.42.2/codemirror.min.css"
rel="stylesheet"
href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.42.2/codemirror.min.css"
/>
</Head>
<Link href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.42.2/codemirror.min.css" />
)
const title = 'Carbon'
const description =
'Carbon is the easiest way to create and share beautiful images of your source code.'
export const MetaTags = () => (
<Head>
<meta charSet="utf-8" />
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="Carbon is the easiest way to create and share beautiful images of your source code."
/>
<meta name="application-name" content="Carbon" />
<meta name="twitter:title" content="Carbon" />
<meta
name="twitter:description"
content="Carbon is the easiest way to create and share beautiful images of your source code."
/>
<meta name="og:title" content="Carbon" />
<meta
name="og:description"
content="Carbon is the easiest way to create and share beautiful images of your source code."
/>
<meta name="description" content={description} />
<meta name="application-name" content={title} />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
<meta name="og:title" content={title} />
<meta name="og:description" content={description} />
<meta name="og:image" content="/static/banner.png" />
<meta name="theme-color" content="#121212" />
<title>Carbon</title>
<title>{title}</title>
<link rel="shortcut icon" href="/static/favicon.ico" />
<link rel="manifest" href="/static/manifest.json" />
</Head>
)
/*
* Before supporting <link rel="preload"> verify that it is widely supported in FireFox
* with out a flag here: https://caniuse.com/#feat=link-rel-preload
*/
export const MetaLinks = () => {
const onBrowser = typeof window !== 'undefined'
return (
<React.Fragment>
<StylesheetLink theme="seti" />
<Link href="/static/themes/seti.css" />
<CodeMirrorLink />
{LOCAL_STYLESHEETS.map(id => (
<StylesheetLink key={id} theme={id} />
<Link key={id} href={`/static/themes/${id}.css`} />
))}
{onBrowser
? CDN_STYLESHEETS.map(theme => <StylesheetLink key={theme.id} theme={theme.id} />)
: null}
{CDN_STYLESHEETS.map(theme => {
const themeDef = THEMES_HASH[theme]
const href = `//cdnjs.cloudflare.com/ajax/libs/codemirror/5.42.2/theme/${themeDef &&
(themeDef.link || themeDef.id)}.min.css`
return <Link key={href} href={href} />
})}
</React.Fragment>
)
}

Loading…
Cancel
Save