Cross Origin/ Cross Domain requests

Cross Origin/ Cross Domain requests


I was working on the Random Quote Machine project an ran into a major CORS problem and I have some questions.

I did a lot of searching and I’d say that 98% of the solutions involved jQuery, which seems like a quick and easy fix. However, my js file is only about 35 lines long.

  1. Is it acceptable to include the entire jQuery library in such a small project just to fix one problem?

Another solution I found using vanilla js was to use the built in fetch() api. However MDN documentation said that some browsers don’t support it.

  1. Is the fetch api ok to use on its own or would I have to also include specific fixes for the browsers that don’t support it?

I also stumbled upon a few vanilla js solutions but they were admittedly over my head as far as understanding everything that was going on so I don’t think I’d even be able to use them.

Any answers or insight would be appreciated. Thanks.


Fetch is absolutely fine unless you need to support IE (or Opera Mini), and if that’s the case, this works just fine:

Also this:

And this:

jQuery is also fine though, if a bit chunky. With any of those, grab them from a CDN - cdnjs is easy, unpkg is good as well.

Also this Stack Overflow answer might be useful


Thanks for the response. All are interesting resources!