0

I load an image and then I try to use this in the PIXI. But PIXI loads image again when I create a PIXI.Texture. If I set crossOrigin to "anonymous" it works fine and doesn't download a picture again. But how it works and what does it mean? Will it work on the internet or it works local only?

That's what I do that download image

image.crossOrigin = "anonymous";
image.src = "filePath";
image.addEventListener("load", doSomethingFunction, false);
mruanova
  • 6,351
  • 6
  • 37
  • 55
Aktash
  • 56
  • 5
  • I found [this](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes), but I still don't understand. – Aktash Jun 01 '16 at 06:37
  • that's a broad question that would require a full article to answer, MDN has [one specifically about images](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image), and you can find others on the web. But basically, it tells your browser that it should make a request to the server with cross-origin headers set, meaning that you do trust the server. If the server is configured to accept this request, it will send the resource, otherwise, it will return an error... – Kaiido Jun 01 '16 at 06:47
  • ... this crossorigin transfer is only important when you do request resources from an other domain, otherwise, the browser will consider it as an unsafe resource and will block some functionnality that may be dangerous (such as some canvas API methods (any export one) and some AudioContext ones. So, if you don't do requests from an other domain, you don't need it. Otherwise, make sure your server is well configured to accept these requests. And if you don't do anything that needs some dangerous methods, you should be fine without it. – Kaiido Jun 01 '16 at 06:50
  • Also, if the browser doesn't use the cache for the image with the attribute when calling the one without it, it is because these are different requests. – Kaiido Jun 01 '16 at 06:52
  • @Kaiido thanks! Does It mean that one of them use `crossOrigin` parameter? – Aktash Jun 01 '16 at 07:01
  • this article is related https://medium.com/@albertogasparin/manipulating-cross-origin-images-with-html-canvas-1e3e8780964c – mruanova Nov 18 '22 at 19:09
  • duplicated from https://stackoverflow.com/questions/18336789/purpose-of-the-crossorigin-attribute – mruanova Nov 18 '22 at 19:11

0 Answers0