You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
Now I send this html using response to client. I have also tell you that I have taken full care about the content/type to be send.
If it's .js, I am sending content/type as "application/javascript".
Here is snippet:
function handler (request, response) {
//console.log(pathname);
var filePath = '.' + url.parse(request.url).pathname;
if (filePath == './')
filePath = './index.htm';
var extname = path.extname(filePath);
var contentType = 'text/html';
switch (extname) {
case '.js':
contentType = 'application/javascript';
break;
case '.css':
contentType = 'text/css';
break;
case '.png':
contentType = 'image/png';
break;
default :
contentType = 'text/html';
}
path.exists(filePath, function(exists) {
if (exists) {
fs.readFile(filePath, function(error, content) {
if (error) {
response.writeHead(500);
response.end();
}
else {
response.writeHead(200, { 'Content-Type': contentType });
response.end(content, 'utf-8');
}
});
}
else {
response.writeHead(404);
response.end();
}
});
//}
}
Now when I receive this html file on client side...it looks something like this.
Notice the missing inline closing tag of script on the top and also notice the separate closing tag of script inserted at the end of document.
Because of this the whole HTML body is treated as part of the script.
Though I have found a workaround for now which is to use separate closing script tag rather than using inline
<script src="/socket.js" type="text/javascript" ></script>
Is this a bug in response or in Browser.
I am using Chrome 21.0
Thanks,
Milan.
Hi,
I have a html file which has a script tag something like this:
<script src="/socket.js" type="text/javascript" />
Now I send this html using response to client. I have also tell you that I have taken full care about the content/type to be send.
If it's .js, I am sending content/type as "application/javascript".
Here is snippet:
function handler (request, response) {
//}
}
Now when I receive this html file on client side...it looks something like this.
<script src="/socket.js" type="text/javascript"> ``` <script src="/socket.js" type="text/javascript">