This recipe revisions all asset files in a dist/assets/
directory using gulp-rev
.
The adds a unique content based hash to each asset file.
The pattern of that hash (/.*-[0-9a-f]{10}\..*/
) is then used to handle these files in Express.js and the Service Worker.
Express.js sets the Cache-Control
header to immutable
.
The Service Worker serves these files directly from cache without ever attempting the server again.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Nuxt2 DatoCMS Plugin | |
* | |
* features: | |
* - $datocms.fetchData: lightweight isomorphic data fetching of GraphQL queries | |
* - $datocms.subscribeToData: real-time data updates using GraphQL queries | |
* - $datocms.state: { error, status, statusMessage } for data subscription | |
* - $datocms.toHead: alias for vue-datocms' toHead method | |
* - <DatocmsImage>: global alias for vue-datocms's Image component | |
* - <DatocmsStructuredText>: global alias for vue-datocms's StructuredText component |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<ClientOnly v-if="$nuxt.isPreview"> | |
<div role="alert"> | |
<span>Preview mode: {{ statusMessage }}</span> | |
<button type="button" @click="exitPreview"> | |
Exit preview | |
</button> | |
</div> | |
</ClientOnly> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const queryDatoGraphQL = require('./query-dato-graphql.js'); | |
module.exports = function (config) { | |
// Custom data file formats (https://www.11ty.dev/docs/data-custom/) | |
config.addDataExtension( | |
'graphql', | |
async (query) => await queryDatoGraphQL({ query }) | |
); | |
// Base Config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Section from './section'; | |
export default App = () => ( | |
<Section> | |
<Section.Header> | |
<Section.Title> My Section </Section.Title> | |
</Section.Header> | |
<Section.Body> | |
Any content here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ('performance' in window) { | |
window.addEventListener('load', function () { | |
var paintMetrics = performance.getEntriesByType('paint'); | |
if (paintMetrics !== undefined && paintMetrics.length > 0){ | |
console.table(paintMetrics.map(function(metric) { | |
return { | |
event: metric.name, | |
startTime: metric.startTime.toFixed(2) + ' ms', | |
duration: metric.duration + ' ms' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request') | |
module.exports = () => (req, res, next) => { | |
const dpr = parseFloat(req.headers.dpr) | |
const width = toInteger(req.headers.width) | |
const viewportWidth = toInteger(req.headers['viewport-width']) | |
const imageWidth = width || Math.round(viewportWidth * dpr) | |
const imageHeight = Math.round(imageWidth/2) | |
request(`http://via.placeholder.com/${imageWidth}x${imageHeight}?text=` + [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function fetchJson(url) { | |
return new Promise((resolve, reject) => { | |
const request = new XMLHttpRequest() | |
request.open('GET', url, true) | |
request.setRequestHeader('Accept', 'application/json') | |
request.onload = function() { | |
if (request.status >= 200 && request.status < 400) { | |
try { | |
const json = JSON.parse(request.responseText) | |
resolve(json) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { h } from 'preact'; | |
import { Details, Summary } from './DetailsSummary'; | |
const App = () => ( | |
<Details> | |
<Summary>This is a summary supporting <code>HTML</code></Summary> | |
<p>... with expandible details.</p> | |
<p>Based on <a href="http://html5doctor.com/summary-figcaption-element/">HTML5 details/summary elements</a>.</p> | |
<p>And added <a href="http://caniuse.com/#feat=details">support for browsers</a> lacking built-in support.</p> | |
</Details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Inline this into the <head> of your HTML document. Replace `PROJECT_ID` and optionally change timeout (now 1000ms). | |
* | |
* Based on https://help.optimizely.com/Set_Up_Optimizely/Synchronous_and_Asynchronous_snippet_loading | |
* Simplified for today's browsers (no `s.async` or `s.type` needed, no need to prefix with `window.`). | |
* Note: risk of using `document.appendChild`: https://www.paulirish.com/2011/surefire-dom-element-insertion/ | |
*/ | |
(function(d) { | |
var s = d.createElement('script'); | |
s.src = 'https://cdn.optimizely.com/js/PROJECT_ID.js'; |
NewerOlder