Skip to content

Commit

Permalink
Improve caching behavior by avoiding 302 redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsEnevoldsen committed Apr 27, 2018
1 parent c9feb1c commit 634ebf9
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/ext.scryfallLinks.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@ $( function () {
cardNameParam = 'exact=' + target.dataset.cardName,
cardSet = target.dataset.cardSet,
cardSetParam = cardSet ? '&set=' + cardSet : '',
formatParam = '&format=image',
versionParam = '&version=normal',
imageSrc = 'https://api.scryfall.com/cards/named?' + cardNameParam + cardSetParam + formatParam + versionParam;
cardJSON = 'https://api.scryfall.com/cards/named?' + cardNameParam + cardSetParam;
if ( tip.loading || content.innerHTML !== '' ) { return; }
tip.loading = true;
// Hide the tooltip until we've finished loaded the image
thisPopper.style.display = 'none';
// fetch() only works on modern browsers
fetch( imageSrc )
fetch( cardJSON )
.then( response => {
if ( !response.ok ) {
throw Error( response.statusText );
}
return response;
} )
.then( response => response.json() )
.then( data => fetch( data.image_uris.normal ) )
.then( response => response.blob() )
.then( blob => {
const url = URL.createObjectURL( blob ),
Expand Down

0 comments on commit 634ebf9

Please sign in to comment.