Slackbot
04/04/2023, 4:37 PMMichael Cooper
04/04/2023, 5:07 PMrequire
"simply" returns a promise, so we can use JS's promise tools to work with it. Assuming unpkg
is returning an error, you can catch it and swap in the other provider
P5 = require('<https://unpkg.com/p5@1.2.0/lib/p5.js').catch(()> => require("<https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js>"))
Michael Cooper
04/04/2023, 5:08 PMPromise.race()
situation where you try both in parallel, that seems heavy handed thoughaaronkyle
04/04/2023, 5:48 PMevalP5 = () => {
let message = '';
try {
require('<https://unpkg.com/p5@1.2.0/lib/p5.js>');
message = 'p5.js loaded successfully.';
return require('<https://unpkg.com/p5@1.2.0/lib/p5.js>')
} catch (error) {
console.log('Failed to load p5.js from <http://unpkg.com|unpkg.com>. Trying cdnjs.com...');
try {
require('<https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js>');
message = 'p5.js loaded successfully.';
return require('<https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js>')
} catch (error) {
console.error('Failed to load p5.js from <http://cdnjs.com|cdnjs.com>:', error);
message = "nothing's working";
return message;
}
}
}
Michael Cooper
04/04/2023, 6:41 PMMichael Cooper
04/04/2023, 6:43 PMFabian Iwand
04/04/2023, 6:47 PMrequire('p5@1.2.0/lib/p5.js')
Brett Cooper
04/05/2023, 12:23 AMP5 = require('<https://unpkg.com/p5@1.6.0/lib/p5.js').catch(()> => require("<https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js>")).catch(() => require("<https://cdn.jsdelivr.net/npm/p5@1.6.0/lib/p5.min.js>"))
Fabian Iwand
04/05/2023, 12:25 AMBrett Cooper
04/05/2023, 12:26 AMFabian Iwand
04/05/2023, 12:28 AMFabian Iwand
04/05/2023, 12:29 AMFabian Iwand
04/05/2023, 12:31 AMif the hosts off will it try different hosts until if gets a win?@Brett Cooper sorry, bit late here, i misread your question: no, it will default to cdn.observableusercontent.com which uses jsdelivr under the hood
Fabian Iwand
04/05/2023, 12:32 AMBrett Cooper
04/05/2023, 12:32 AMaaronkyle
04/05/2023, 12:33 AMaaronkyle
04/05/2023, 12:33 AMaaronkyle
04/05/2023, 12:34 AMaaronkyle
04/05/2023, 12:35 AMFabian Iwand
04/05/2023, 12:35 AMaaronkyle
04/05/2023, 12:36 AMFabian Iwand
04/05/2023, 12:37 AMBrett Cooper
04/05/2023, 12:37 AM