JS new image if not in cache









up vote
0
down vote

favorite












I'm loading some images via XHR and play them as sequence on canvas element.



I preload images first and after all images are preloaded I call for every image



const im = new Image();
im.src = image;
ctx.drawImage(im ,0,0);


where image is a blob url



The problem is, when animation loops, browser make new requests for every frame. As images are cahced, it takes no time, but continuously builds thousands of requests.



I still can not pass blob url to canvas, as it does not support it, and if I try to path the actual image url, it does not work, because these urls are not preloaded, only the blob urls.



Is there a way to omit request with new Image() if src url is cached?



Thanks



P.S. To clarify



As images are preloaded for the first time, they are actually preloaded
enter image description here



And as i call new Image() and pass blobUrls as src, they are loaded from cache
enter image description here










share|improve this question



















  • 4




    Load the images and store them in an array. Then play the movie from the array.
    – Chris G
    Nov 8 at 23:35







  • 1




    Canvas2D might not, but WebGL certainly allows you to use blob URLs as textures and even (and that's probably far more practical?) lets you assign a stream to a texture, so you aren't working with 1000+ images but a (much smaller) mp4 or something.
    – Mike 'Pomax' Kamermans
    Nov 8 at 23:37










  • @Mike you mean webgl has a synchronous fetch algorithm in its texture API? Could you point to some resources about it. Sobakinet, even loading an Image from a blobURI is async anyway. So indeed as correctly said ChrisG, preload your images with img elements and store these elements rather than Blobs (you'll save twice memory usage btw).
    – Kaiido
    Nov 8 at 23:45






  • 1




    Highly related stackoverflow.com/questions/42453031/…
    – Kaiido
    Nov 8 at 23:47










  • There are both - blob urls and image urls stored in array. But if I use image urls instead of blob urls, browser loads them again, because only blobs url are preloaded.....
    – Sobakinet
    Nov 8 at 23:47














up vote
0
down vote

favorite












I'm loading some images via XHR and play them as sequence on canvas element.



I preload images first and after all images are preloaded I call for every image



const im = new Image();
im.src = image;
ctx.drawImage(im ,0,0);


where image is a blob url



The problem is, when animation loops, browser make new requests for every frame. As images are cahced, it takes no time, but continuously builds thousands of requests.



I still can not pass blob url to canvas, as it does not support it, and if I try to path the actual image url, it does not work, because these urls are not preloaded, only the blob urls.



Is there a way to omit request with new Image() if src url is cached?



Thanks



P.S. To clarify



As images are preloaded for the first time, they are actually preloaded
enter image description here



And as i call new Image() and pass blobUrls as src, they are loaded from cache
enter image description here










share|improve this question



















  • 4




    Load the images and store them in an array. Then play the movie from the array.
    – Chris G
    Nov 8 at 23:35







  • 1




    Canvas2D might not, but WebGL certainly allows you to use blob URLs as textures and even (and that's probably far more practical?) lets you assign a stream to a texture, so you aren't working with 1000+ images but a (much smaller) mp4 or something.
    – Mike 'Pomax' Kamermans
    Nov 8 at 23:37










  • @Mike you mean webgl has a synchronous fetch algorithm in its texture API? Could you point to some resources about it. Sobakinet, even loading an Image from a blobURI is async anyway. So indeed as correctly said ChrisG, preload your images with img elements and store these elements rather than Blobs (you'll save twice memory usage btw).
    – Kaiido
    Nov 8 at 23:45






  • 1




    Highly related stackoverflow.com/questions/42453031/…
    – Kaiido
    Nov 8 at 23:47










  • There are both - blob urls and image urls stored in array. But if I use image urls instead of blob urls, browser loads them again, because only blobs url are preloaded.....
    – Sobakinet
    Nov 8 at 23:47












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm loading some images via XHR and play them as sequence on canvas element.



I preload images first and after all images are preloaded I call for every image



const im = new Image();
im.src = image;
ctx.drawImage(im ,0,0);


where image is a blob url



The problem is, when animation loops, browser make new requests for every frame. As images are cahced, it takes no time, but continuously builds thousands of requests.



I still can not pass blob url to canvas, as it does not support it, and if I try to path the actual image url, it does not work, because these urls are not preloaded, only the blob urls.



Is there a way to omit request with new Image() if src url is cached?



Thanks



P.S. To clarify



As images are preloaded for the first time, they are actually preloaded
enter image description here



And as i call new Image() and pass blobUrls as src, they are loaded from cache
enter image description here










share|improve this question















I'm loading some images via XHR and play them as sequence on canvas element.



I preload images first and after all images are preloaded I call for every image



const im = new Image();
im.src = image;
ctx.drawImage(im ,0,0);


where image is a blob url



The problem is, when animation loops, browser make new requests for every frame. As images are cahced, it takes no time, but continuously builds thousands of requests.



I still can not pass blob url to canvas, as it does not support it, and if I try to path the actual image url, it does not work, because these urls are not preloaded, only the blob urls.



Is there a way to omit request with new Image() if src url is cached?



Thanks



P.S. To clarify



As images are preloaded for the first time, they are actually preloaded
enter image description here



And as i call new Image() and pass blobUrls as src, they are loaded from cache
enter image description here







javascript canvas blob preload






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 23:59

























asked Nov 8 at 23:33









Sobakinet

3271525




3271525







  • 4




    Load the images and store them in an array. Then play the movie from the array.
    – Chris G
    Nov 8 at 23:35







  • 1




    Canvas2D might not, but WebGL certainly allows you to use blob URLs as textures and even (and that's probably far more practical?) lets you assign a stream to a texture, so you aren't working with 1000+ images but a (much smaller) mp4 or something.
    – Mike 'Pomax' Kamermans
    Nov 8 at 23:37










  • @Mike you mean webgl has a synchronous fetch algorithm in its texture API? Could you point to some resources about it. Sobakinet, even loading an Image from a blobURI is async anyway. So indeed as correctly said ChrisG, preload your images with img elements and store these elements rather than Blobs (you'll save twice memory usage btw).
    – Kaiido
    Nov 8 at 23:45






  • 1




    Highly related stackoverflow.com/questions/42453031/…
    – Kaiido
    Nov 8 at 23:47










  • There are both - blob urls and image urls stored in array. But if I use image urls instead of blob urls, browser loads them again, because only blobs url are preloaded.....
    – Sobakinet
    Nov 8 at 23:47












  • 4




    Load the images and store them in an array. Then play the movie from the array.
    – Chris G
    Nov 8 at 23:35







  • 1




    Canvas2D might not, but WebGL certainly allows you to use blob URLs as textures and even (and that's probably far more practical?) lets you assign a stream to a texture, so you aren't working with 1000+ images but a (much smaller) mp4 or something.
    – Mike 'Pomax' Kamermans
    Nov 8 at 23:37










  • @Mike you mean webgl has a synchronous fetch algorithm in its texture API? Could you point to some resources about it. Sobakinet, even loading an Image from a blobURI is async anyway. So indeed as correctly said ChrisG, preload your images with img elements and store these elements rather than Blobs (you'll save twice memory usage btw).
    – Kaiido
    Nov 8 at 23:45






  • 1




    Highly related stackoverflow.com/questions/42453031/…
    – Kaiido
    Nov 8 at 23:47










  • There are both - blob urls and image urls stored in array. But if I use image urls instead of blob urls, browser loads them again, because only blobs url are preloaded.....
    – Sobakinet
    Nov 8 at 23:47







4




4




Load the images and store them in an array. Then play the movie from the array.
– Chris G
Nov 8 at 23:35





Load the images and store them in an array. Then play the movie from the array.
– Chris G
Nov 8 at 23:35





1




1




Canvas2D might not, but WebGL certainly allows you to use blob URLs as textures and even (and that's probably far more practical?) lets you assign a stream to a texture, so you aren't working with 1000+ images but a (much smaller) mp4 or something.
– Mike 'Pomax' Kamermans
Nov 8 at 23:37




Canvas2D might not, but WebGL certainly allows you to use blob URLs as textures and even (and that's probably far more practical?) lets you assign a stream to a texture, so you aren't working with 1000+ images but a (much smaller) mp4 or something.
– Mike 'Pomax' Kamermans
Nov 8 at 23:37












@Mike you mean webgl has a synchronous fetch algorithm in its texture API? Could you point to some resources about it. Sobakinet, even loading an Image from a blobURI is async anyway. So indeed as correctly said ChrisG, preload your images with img elements and store these elements rather than Blobs (you'll save twice memory usage btw).
– Kaiido
Nov 8 at 23:45




@Mike you mean webgl has a synchronous fetch algorithm in its texture API? Could you point to some resources about it. Sobakinet, even loading an Image from a blobURI is async anyway. So indeed as correctly said ChrisG, preload your images with img elements and store these elements rather than Blobs (you'll save twice memory usage btw).
– Kaiido
Nov 8 at 23:45




1




1




Highly related stackoverflow.com/questions/42453031/…
– Kaiido
Nov 8 at 23:47




Highly related stackoverflow.com/questions/42453031/…
– Kaiido
Nov 8 at 23:47












There are both - blob urls and image urls stored in array. But if I use image urls instead of blob urls, browser loads them again, because only blobs url are preloaded.....
– Sobakinet
Nov 8 at 23:47




There are both - blob urls and image urls stored in array. But if I use image urls instead of blob urls, browser loads them again, because only blobs url are preloaded.....
– Sobakinet
Nov 8 at 23:47

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217740%2fjs-new-image-if-not-in-cache%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53217740%2fjs-new-image-if-not-in-cache%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ