Skip to content

Commit a587220

Browse files
authored
Merge pull request #8270 from processing/font-fetch-head
Add fallback for HTTP HEAD requests
2 parents e1c379a + 088eab5 commit a587220

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/type/p5.Font.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,15 @@ function font(p5, fn) {
14811481
let isCSS = path.includes('@font-face');
14821482

14831483
if (!isCSS) {
1484-
const info = await fetch(path, { method: 'HEAD' });
1484+
let info;
1485+
try {
1486+
info = await fetch(path, { method: 'HEAD' });
1487+
} catch (e) {
1488+
// Sometimes files fail when requested with HEAD. Fallback to a
1489+
// regular GET. It loads more data, but at least then it's cached
1490+
// for the likely case when we have to fetch the whole thing.
1491+
info = await fetch(path);
1492+
}
14851493
const isCSSFile = info.headers.get('content-type')?.startsWith('text/css');
14861494
if (isCSSFile) {
14871495
isCSS = true;

0 commit comments

Comments
 (0)