javascript - Loading .js files on client side with page served by Node JS -


i have following simple js file, familiar who's used socket.io nodejs , express framework:

var express = require('express'),     app = express(),     server = require('http').createserver(app),     io = require('socket.io').listen(server);  server.listen(8374);  // routing app.get('/', function (req, res) {     res.sendfile(__dirname + '/index.html'); }); 

in index.html, have following line of code:

<script src="/socket.io/socket.io.js"></script> 

i have done experimenting pathnames , serving/mounting , still don't understand how client-side line manages work. answer this question says listening server, io handles incoming socket.io requests.

...

my question is: can done other client-side js files?

for example, there easy way bundle jquery can handled in same way? @ moment can put file in folder public , use express' app.use() method in index.html can include line:

<script src="/public/jquery-1.9.1.js"></script> 

is there way manage jquery dependency can nodejs?

i'm thinking end result this:

server-side:

var jquery = require('jquery'); 

client-side:

<script src="jquery/jquery-1.9.1.js"></script> 

i'm not sure using modules host specific files, more time-efficient host file when it's requested:

app.get("/", function (req, res) {     res.sendfile(__dirname + "/index.html"); }); app.get("/public/jquery-1.9.1.js", function (req, res) {     res.sendfile(__dirname + "/public/jquery-1.9.1.js"); }); 

i don't use express, please excuse mistakes.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -