While using html
for long time, we used to include the script tags calling for some file within the same folder of the html
page, or any other folder but we have to include the exact source of it, something like that:
<script src = "the source of the file and its name"></script>
Using socket.io website, there is index.html
file, and the script tag is like that:
<script src="/socket.io/socket.io.js"></script>
but in fact the real source of socket.io.js
file is in the node modules, even-though the website is working well, if I include the real source of this file, the website will crash.
I am really curious about the reason of this strange situation, someone explain it to me, please!
While using html
for long time, we used to include the script tags calling for some file within the same folder of the html
page, or any other folder but we have to include the exact source of it, something like that:
<script src = "the source of the file and its name"></script>
Using socket.io website, there is index.html
file, and the script tag is like that:
<script src="/socket.io/socket.io.js"></script>
but in fact the real source of socket.io.js
file is in the node modules, even-though the website is working well, if I include the real source of this file, the website will crash.
I am really curious about the reason of this strange situation, someone explain it to me, please!
https://cdnjs./libraries/socket.io
– Daniel Krom
Commented
Jun 13, 2017 at 14:16
<script src="/socket.io/socket.io.js"></script>
works
– Nikhil Nanjappa
Commented
Jun 13, 2017 at 14:18
Refused to execute script from 'https://cdnjs./libraries/socket.io' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
@DanielKrom
– Zainab Hammami
Commented
Jun 13, 2017 at 14:19
The website crashes rightly because, your Socket.IO server will handle serving the correct version of the Socket.IO client library; you should not be using one from anywhere else.
How it works?
you wrap your HTTP server in Socket.IO like this:
var io = require('socket.io')(http);
and it intercepts requests for "/socket.io/socket.io.js" and sends the appropriate response automatically. That is why <script src="/socket.io/socket.io.js"></script>
works and the others don't.
Meaning if the server is running, socket.io.js
should be readily available.