Adding CORS header to static assets in Laravel App

Sam Ngu
2 min readSep 8, 2020
Image from Stencil

Sometimes we need to fetch static resources (PDF files, images, videos etc)from a server via a HTTP client in the browser, eg. AJAX, Fetch or Axios. So we try this in JavaScript:

fetch('https://mysite.com/assets/some_pdf.pdf);

But we see our good old friend CORS error :)

Resource from origin 'https://mysite.com' has been…

--

--