Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3cb205c

Browse files
authored
feat: improve card loading speed (anuraghazra#2124)
* feat: improve card loading timesThis commit adds the `stale-while-revalidate` option to speed up thecard loading times.* mend
1 parentf07cd13 commit3cb205c

File tree

5 files changed

+54
-9
lines changed

5 files changed

+54
-9
lines changed

‎api/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ export default async (req, res) => {
6161
CONSTANTS.ONE_DAY,
6262
);
6363

64-
res.setHeader("Cache-Control",`public, max-age=${cacheSeconds}`);
64+
res.setHeader(
65+
"Cache-Control",
66+
`max-age=${
67+
cacheSeconds/2
68+
}, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
69+
);
6570

6671
returnres.send(
6772
renderStatsCard(stats,{

‎api/pin.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ export default async (req, res) => {
5858
cacheSeconds=CONSTANTS.FOUR_HOURS;
5959
}
6060

61-
res.setHeader("Cache-Control",`public, max-age=${cacheSeconds}`);
61+
res.setHeader(
62+
"Cache-Control",
63+
`max-age=${
64+
cacheSeconds/2
65+
}, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
66+
);
6267

6368
returnres.send(
6469
renderRepoCard(repoData,{

‎api/top-langs.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ export default async (req, res) => {
5252
CONSTANTS.ONE_DAY,
5353
);
5454

55-
res.setHeader("Cache-Control",`public, max-age=${cacheSeconds}`);
55+
res.setHeader(
56+
"Cache-Control",
57+
`max-age=${
58+
cacheSeconds/2
59+
}, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
60+
);
5661

5762
returnres.send(
5863
renderTopLanguages(topLangs,{

‎api/wakatime.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ export default async (req, res) => {
5252
cacheSeconds=CONSTANTS.FOUR_HOURS;
5353
}
5454

55-
res.setHeader("Cache-Control",`public, max-age=${cacheSeconds}`);
55+
res.setHeader(
56+
"Cache-Control",
57+
`max-age=${
58+
cacheSeconds/2
59+
}, s-maxage=${cacheSeconds}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
60+
);
5661

5762
returnres.send(
5863
renderWakatimeCard(stats,{

‎tests/api.test.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ describe("Test /api/", () => {
160160

161161
expect(res.setHeader.mock.calls).toEqual([
162162
["Content-Type","image/svg+xml"],
163-
["Cache-Control",`public, max-age=${CONSTANTS.FOUR_HOURS}`],
163+
[
164+
"Cache-Control",
165+
`max-age=${CONSTANTS.FOUR_HOURS/2}, s-maxage=${
166+
CONSTANTS.FOUR_HOURS
167+
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
168+
],
164169
]);
165170
});
166171

@@ -170,7 +175,12 @@ describe("Test /api/", () => {
170175

171176
expect(res.setHeader.mock.calls).toEqual([
172177
["Content-Type","image/svg+xml"],
173-
["Cache-Control",`public, max-age=${15000}`],
178+
[
179+
"Cache-Control",
180+
`max-age=7500, s-maxage=${15000}, stale-while-revalidate=${
181+
CONSTANTS.ONE_DAY
182+
}`,
183+
],
174184
]);
175185
});
176186

@@ -191,7 +201,12 @@ describe("Test /api/", () => {
191201

192202
expect(res.setHeader.mock.calls).toEqual([
193203
["Content-Type","image/svg+xml"],
194-
["Cache-Control",`public, max-age=${CONSTANTS.ONE_DAY}`],
204+
[
205+
"Cache-Control",
206+
`max-age=${CONSTANTS.ONE_DAY/2}, s-maxage=${
207+
CONSTANTS.ONE_DAY
208+
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
209+
],
195210
]);
196211
}
197212

@@ -202,7 +217,12 @@ describe("Test /api/", () => {
202217

203218
expect(res.setHeader.mock.calls).toEqual([
204219
["Content-Type","image/svg+xml"],
205-
["Cache-Control",`public, max-age=${CONSTANTS.FOUR_HOURS}`],
220+
[
221+
"Cache-Control",
222+
`max-age=${CONSTANTS.FOUR_HOURS/2}, s-maxage=${
223+
CONSTANTS.FOUR_HOURS
224+
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
225+
],
206226
]);
207227
}
208228

@@ -212,7 +232,12 @@ describe("Test /api/", () => {
212232

213233
expect(res.setHeader.mock.calls).toEqual([
214234
["Content-Type","image/svg+xml"],
215-
["Cache-Control",`public, max-age=${CONSTANTS.FOUR_HOURS}`],
235+
[
236+
"Cache-Control",
237+
`max-age=${CONSTANTS.FOUR_HOURS/2}, s-maxage=${
238+
CONSTANTS.FOUR_HOURS
239+
}, stale-while-revalidate=${CONSTANTS.ONE_DAY}`,
240+
],
216241
]);
217242
}
218243
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp