Francis Stalin
Francis Stalin

Reputation: 449

How to render all js file in server with nodejs

i have designed my webpage using html with jquery.My webpage is loading very slow because I include more js libraries.if i will do some dynamic operation it will call javascript library and do some manipulation in client side so its getting loaded slowly.

now i come to my question :

i want to compile all my javascript files in server side using nodejs.i have to give only html output to client because client will not do any manipulation it will show only html .

i want like this:

1.if server request a page 2.the request go to nodejs server 3.nodejs should compile all linked js,css 4.fially it will render dynamic content into single html 5.return to browser 6.browser will display the html file

i am not sure whether it is possible in nodejs because i am beginner to this nodejs technology.pls help me if u can thanks in advance.

if my question is wrong pls forgive me

Upvotes: 0

Views: 1319

Answers (2)

m3kh
m3kh

Reputation: 7941

IMO, you need a Node.js Web Application Framework. There are plenty of them on the web.

Some examples:

Upvotes: 1

1Mayur
1Mayur

Reputation: 3485

var express = require('express')
  , app = express()
  , http = require('http')
  , server = http.createServer(app);

server.listen(3000);
console.log('Server Started @ 3000');

app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});
app.get('/index.html', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});
app.get('/game.html', function (req, res) {
    res.sendfile(__dirname + '/game.html');
});
app.get('/:url', function (req, res) {  
    res.sendfile(__dirname + req.url);
});
app.get('/:url[.js]', function (req, res) {
    res.sendfile(__dirname + req.url);
});
app.get('/:url[.css]', function (req, res) {    
    res.sendfile(__dirname + req.url);
});
app.get('/images/:url[.png]', function (req, res) {
    res.sendfile(__dirname + req.url);
});

Try this I hope you will get some idea

if my answer is wrong pls forgive me

Upvotes: 2

Related Questions