Skip to content

Commit f535b05

Browse files
committed
Add fallback for HTTP HEAD requests
1 parent 60ef55e commit f535b05

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
@@ -1480,7 +1480,15 @@ function font(p5, fn) {
14801480
let isCSS = path.includes('@font-face');
14811481

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

0 commit comments

Comments
 (0)