Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

echo('<script src="https://cdn.jsdelivr.net/npm/@splidejs/splide@4.0.15/dist/js/splide.min.js"></script>');
seems to work fine. At least no messages in the browser console.

echo('<script src="'.$_SERVER['DOCUMENT_ROOT'].'/jscripts/splide.min.js"></script>');


Seems not to work fine, I get this error:
Quote:
Refused to execute script from 'https://www...../jscripts/splide.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.


Searching the internet I've seen only people saying I should change the mime type and add type="application/json" instead of "application/javascript". No need to say none of them worked for me.

In my htaccess there is:
Quote:
Header set X-Content-Type-Options "nosniff"


Any idea?

As always thank you in advance!

What I have tried:

I've tried to search Google, changing the MIME type, loading the script from another web site...
Posted
Updated 4-Sep-22 22:37pm
Comments
Member 15627495 4-Sep-22 23:46pm    
the path you use is too deep on 'root server' ....
the www is inner server, and not known by 'user computer/client' when calling the resource.

try something from one folder after , so the first folder for a base of path.

src="jscripts/splide.min.js"

1 solution

Member 15627495 is pretty much correct, the DOCUMENT_ROOT variable is designed to produce the path to the directory where the file is executing on the server, not in the browser. I don't know how your error message is producing 'https://www...../jscripts/splide.min.js', I wouldn't expect that URL to begin with https://

The reason you're getting a text/html response is probably because the server is producing a 404 error for that address, and chances are it's returning a generic HTML page. Try viewing the source of the page and see what the produced full URL is, then see if you can access it directly via a browser tab address bar.

If your script files are always from https://abc.xyz/jscripts/... then consider just using /jscripts/splide.min.js which will allow the browser to load the script even from longer URL paths.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900