Answer the question
In order to leave comments, you need to log in
How to give the browser a JavaScript file?
In response to a request:
Remote Address:127.0.0.1:80
Request URL:http://localhost/js/jquery.js
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,ru;q=0.6,de;q=0.4
Connection:keep-alive
Host:localhost
User-Agent:Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36
Response Headersview source
Connection:keep-alive
Content-Type:text/javascript
Date:Mon, 03 Nov 2014 16:17:10 GMT
Transfer-Encoding:chunked
<!doctype html>
<html>
<head>
<script src="js/jquery.js"></script>
...
path = './js/jquery.js';
var stream = fs.createReadStream(path, 'utf8');
stream.on('readable', function () {
response.writeHead(200, {'Content-Type': 'text/javascript'});
var out;
while ((out = stream.read()) !== null)
response.write(out, 'utf8');
});
stream.once('end', function () {
response.end();
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question