Can I have the following config in route/index.js ?
exports.PageA = function(req, res) {
...
...
if(req.method == 'GET') {
if (condition1) {
//PageA has 2 .js files
res.render('PageA', { title: 'A', layout: false});
}
else {
//PageB has 2 + 2 .js files
res.render('PageB', { title: 'B', layout: false});
}
}
else {
res.render('PageC', { title: 'B', layout:'some_other_layout' });
}
};
Case: mywebsite.com/PageA renders correctly when condition1 passes (with all scripts loaded and executed correctly)
Issue : But when condition1 fails, I get PageB rendered, javascripts in PageB.ejs are rendered but not executed, say, on $document.Ready(). Strangely if I 'Refresh' the already rendered PageB in browser, javascripts are then executed correctly.
As a piece of info: I use defer="defer" tag in all "< script >..."
What am I missing here?
Your problem is entirely on the client side. Attribute "defer" supported only in Internet Explorer and Firefox at this moment. I think your problem is that the scripts are loaded in the wrong sequence. Check your browser console for errors. When you re-load a page, the scripts are loaded from the browser cache. It's faster. Therefore, the error may not appear in this situation.