Currently I'm storing a lot of static image files on my own Node-Express server, and accessing them throughout the code via relative url (ex: <img src="/img/foo/bar.png">
). I'm moving all the images to Amazon S3, so now this url would have to be https://myimagebucket.s3.amazonaws.com/img/foo/bar.png
. However, changing every single image reference to include this absolute url would be a nightmare, so I set up some Express middleware that would redirect any image requests like so:
app.use('/img', function(req, res, next) {
res.redirect('https://myimagebucket.s3.amazonaws.com' + req.originalUrl);
});
Performance-wise, is this a good idea, or does this negate the benefits of hosting the images somewhere else?
Or is it best practice to specify the host in the view, meaning I should just take the long route of changing all of the image references manually?