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
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.
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.