Answer the question
In order to leave comments, you need to log in
How to download js code from another site?
I use two sites. I want to use the js file I wrote from the first site on the second site. I'm trying to load code with fetch or import(). I get a CORS error in the console. How to download js code?
If it was html I would insert the headers with php in the import file and it rolls over:
<?php
header('Content-type: text/html');
header('Access-Control-Allow-Origin: *');
?>
I try to insert something like this at the beginning of the imported file, but it doesn't help:
let myHeaders = new Headers();
myHeaders.set('Content-type', 'text/javascript');
myHeaders.set('Access-Control-Allow-Origin', '*');
Answer the question
In order to leave comments, you need to log in
Write a simple php script with file_get_contents(), make a request from the front to this script, and let the script get the file from a third-party server
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question