Skip to content

Commit 1e4aa6d

Browse files
authored
Try fetching without proxy first
When fetching a resource, try directly first. If it throws an error, then try with proxies. Fixes #95 Should also reduce drastically the petitions to the proxy servers (will only be made if the non-proxy fails)
1 parent 2c23eba commit 1e4aa6d

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

htmlpreview.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989

9090
var fetchProxy = function (url, options, i) {
9191
var proxy = [
92+
'', // try without proxy first
9293
'https://cors-anywhere.herokuapp.com/',
9394
'https://yacdn.org/proxy/',
9495
'https://api.codetabs.com/v1/proxy/?quest='
@@ -104,10 +105,7 @@
104105
};
105106

106107
if (url && url.indexOf(location.hostname) < 0)
107-
fetch(url).then(function (res) {
108-
if (!res.ok) throw new Error('Cannot load ' + url + ': ' + res.status + ' ' + res.statusText);
109-
return res.text();
110-
}).then(loadHTML).catch(function (error) {
108+
fetchProxy(url, null, 0).then(loadHTML).catch(function (error) {
111109
console.error(error);
112110
previewForm.style.display = 'block';
113111
previewForm.innerText = error;

0 commit comments

Comments
 (0)