This repository was archived by the owner on Apr 22, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
This repository was archived by the owner on Apr 22, 2023. It is now read-only.
inline closing script tag misunderstood by response #3351
Copy link
Copy link
Closed
Description
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) {
//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.
<script src="/socket.js" type="text/javascript"> ``` <script src="/socket.js" type="text/javascript">
...
...
...
</script>
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.
Metadata
Metadata
Assignees
Labels
No labels