Reputation: 26930
In html:
<script type="text/javascript" src="/layout/load_scripts?jquery.validate.min.js,jquery-1.5.1.min.js,jquery-ui-1.8.11.min.js,jquery.unobtrusive-ajax.min.js,jquery.validate.unobtrusive.min.js"></script>
on server:
load_scripts: function (context) {
var combined_script = '';
var script_names = context.parameters.split(',');
for (var i = 0; i < script_names.length; i++) {
combined_script += fs.readFileSync('./content/scripts/global/' + script_names[i]);
}
context.response.writeHead(200, { 'Content-Type': 'application/javascript' });
context.response.end(combined_script);
}
But the script does not load. Please help
Upvotes: 1
Views: 75
Reputation: 34632
Why would you use readFileSync for something like that? You could be reading all the files at the same time. I would probably solve this with the async library and have a more functional approach.
async.map(['file1','file2','file3'], fs.readFile, function(err, results){
results.join(''); // This is your string.
});
More info on the Async GitHub page.
Upvotes: 1
Reputation: 21810
at first glance, i'd debug like this:
fs.readFileSync()
is actually reading files... ( printing to console should work )And also, it doesn't look like you're returning your combined script anywhere.
Upvotes: 1