惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
M
MIT News - Artificial intelligence
量子位
N
Netflix TechBlog - Medium
The Cloudflare Blog
The GitHub Blog
The GitHub Blog
P
Proofpoint News Feed
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
B
Blog
博客园_首页
博客园 - Franky
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
MongoDB | Blog
MongoDB | Blog
云风的 BLOG
云风的 BLOG
爱范儿
爱范儿
H
Help Net Security
Y
Y Combinator Blog
Stack Overflow Blog
Stack Overflow Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell

The Eleventy Firehose

New Sponsorship Tiers for the Build Awesome Kickstarter Securely Publishing our Packages to npm Back Build Awesome Pro and make it easier to build for the web! The Possum Mascot, now with additional Awesome Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) Release Import v1.0.20 · 11ty/import Release Import v1.0.21 · 11ty/import Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) Cozy Keyboard Build and Build Awesome AMA Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty.dev) A few demos of Editing and Collaboration in Build Awesome Pro (as always, AMA!) Build Awesome (11ty) (@11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Bluesky: May 6, 2026 at 7:54:00 PM UTC An Awesome Theming Demo with Dave Gandy (and more Build Awesome AMA) Build Awesome (11ty) (@11ty@neighborhood.11ty.dev) Release v8.0.0 · 11ty/eleventy-plugin-vite Build Awesome Pro Kickstarter AMA
Quick Tip: Cache Data Requests
Zach Leather · 2026-06-07 · via The Eleventy Firehose

In Quick Tip #007, we described a method to fetch data from an API at build time (in this example it was GitHub Stargazers) to display on your site.

However, if you’re working on your site locally, you probably don’t want every Eleventy build to make a request to an external API call. You’d hit the rate limit pretty quickly (on GitHub, 60 per hour) and each request would slow down your build times!

Now there is an easier way. You can use the eleventy-fetch utility to cache these requests to save on both API limits and build performance!

npm install @11ty/eleventy-fetch

Features

  • Makes at most one network request in the duration time span—save on both your API limit count and your build time!
  • Easy graceful handling of bad network requests to an API.
  • If your cache expires and it makes another request, and that request fails—it automatically falls back to the expired cache entry! This is especially useful if you’re developing without a network connection (airplane-driven-development)—your site will work the same as it did with the network connection—no changes required to your local development environment.

Example

This code is currently in use on the Eleventy web site to display GitHub stars in the footer. Check out the full source code.

import Fetch from "@11ty/eleventy-fetch";

export default async function () {
	// https://developer.github.com/v3/repos/#get
	let json = await Fetch("https://api.github.com/repos/11ty/eleventy", {
		duration: "1d", // 1 day
		type: "json", // also supports "text" or "buffer"
	});

	return {
		stargazers: json.stargazers_count,
	};
};
const Fetch = require("@11ty/eleventy-fetch");

module.exports = async function () {
	// https://developer.github.com/v3/repos/#get
	let json = await Fetch("https://api.github.com/repos/11ty/eleventy", {
		duration: "1d", // 1 day
		type: "json", // also supports "text" or "buffer"
	});

	return {
		stargazers: json.stargazers_count,
	};
};

Failing Even More Gracefully

Wrap the above code in a nice try catch allows you to return a fake data set if the very first request fails (no expired cache entry is available). Note that if there is already an expired cache entry available, we use that instead.

import Fetch from "@11ty/eleventy-fetch";

export default async function () {
	try {
		// https://developer.github.com/v3/repos/#get
		let json = await Fetch(
			"https://api.github.com/repos/11ty/eleventy",
			{
				duration: "1d", // 1 day
				type: "json", // also supports "text" or "buffer"
			}
		);

		return {
			stargazers: json.stargazers_count,
		};
	} catch (e) {
		console.log("Failed getting GitHub stargazers count, returning 0");
		return {
			stargazers: 0,
		};
	}
};
const Fetch = require("@11ty/eleventy-fetch");

module.exports = async function () {
	try {
		// https://developer.github.com/v3/repos/#get
		let json = await Fetch(
			"https://api.github.com/repos/11ty/eleventy",
			{
				duration: "1d", // 1 day
				type: "json", // also supports "text" or "buffer"
			}
		);

		return {
			stargazers: json.stargazers_count,
		};
	} catch (e) {
		console.log("Failed getting GitHub stargazers count, returning 0");
		return {
			stargazers: 0,
		};
	}
};