Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
reegodev committed Nov 20, 2021
1 parent 358a05d commit c09dc32
Show file tree
Hide file tree
Showing 30 changed files with 3,435 additions and 2 deletions.
20 changes: 20 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
plugins: ['svelte3', '@typescript-eslint'],
ignorePatterns: ['*.cjs'],
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
settings: {
'svelte3/typescript': () => require('typescript')
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2019
},
env: {
browser: true,
es2017: true,
node: true
}
};
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
node_modules
/build
/.svelte-kit
/package
.env
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100
}
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# sveltekit-isr
Incremental static regeneration for SvelteKit on Cloudflare Workers
# Incremental static regeneration (ISR) for SvelteKit on Cloudflare Pages

This is a small Covid19 Tracker demo that uses SvelteKit to show that Cloudflare supports framework-agnostic Incremental Static Regeneration (ISR).<br>
The homepage is regenerated every 24 hours, while the country pages are regenerated every 4 hours.<br>
If you inspect the page response headers, you can see that even if there has been a cache miss, the response still contains a stale version.

## What is ISR?

The acronym has been coined by Vercel, and it's a method of rendering static pages on demand instead of generating all pages at build time like a normal SSG does. This allows websites with thousands of pages to keep build times low.<br>
NextJS has built-in support for ISR when deployed on Vercel.

You can read more about ISR on [Vercel official documentation](https://vercel.com/docs/concepts/next.js/incremental-static-regeneration)

## How do you achieve ISR on Cloudflare?

For a framework-agnostic and detailed explanation, please read my [blog post](https://reego.dev/blog/isr-on-cloudflare-pages).

If you are just curious about SvelteKit implementation, check the [adapter](https://github.com/reegodev/sveltekit-isr/tree/main/adapter) folder.

## License

MIT
19 changes: 19 additions & 0 deletions adapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default function ({ pages = 'build', assets = pages, fallback } = {}) {
return {
name: 'cloudflare-pages-isr-adapter',

async adapt({ utils }) {
utils.rimraf(assets);
utils.rimraf(pages);

utils.copy_static_files(assets);
utils.copy_client_files(assets);

await utils.prerender({
fallback,
all: !fallback,
dest: pages
});
}
};
}
1 change: 1 addition & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\[\[path\]\].js
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "my-app",
"version": "0.0.1",
"scripts": {
"dev": "svelte-kit dev",
"build": "svelte-kit build",
"preview": "svelte-kit preview",
"check": "svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
},
"devDependencies": {
"@sveltejs/kit": "next",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"autoprefixer": "^10.4.0",
"cssnano": "^5.0.11",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-svelte3": "^3.2.1",
"postcss": "^8.3.11",
"prettier": "^2.4.1",
"prettier-plugin-svelte": "^2.4.0",
"svelte": "^3.42.6",
"svelte-check": "^2.2.6",
"svelte-preprocess": "^4.9.4",
"tailwindcss": "^2.2.19",
"tslib": "^2.3.1",
"typescript": "^4.4.3"
},
"type": "module",
"dependencies": {
"@cloudflare/kv-asset-handler": "^0.2.0",
"axios": "^0.24.0",
"date-fns": "^2.26.0",
"simple-svelte-autocomplete": "^2.2.4",
"svelte-autocomplete": "^0.0.4"
}
}
Loading

0 comments on commit c09dc32

Please sign in to comment.