Is it okay for an img to have src value with redirect to another page?
In view, I have img:
<img src='/images/fileName'/>
In app.js
app.get('/images/:fileName', subject.image);
This is my route:
exports.image = function(req, res){
var fileName = req.fileName;
fs.exists(fileName, function(exists){
if (exists) {
res.sendfile(imagePath);
}else{
res.redirect('http://gravatar.com/avatar/_some_hash');
}
});
}
My code works, but is it okay to use res.redirect if image does not exist?
Thanks
Yes, it's ok to redirect. In the end its just a GET to the HTTP server and the browser will follow the redirect.
As mentioned in this question: (Is it OK to HTTP redirect images?) you might not want do to that for lots of images.