I'm securising my RESTful php API by autorizing only HTTP requests with a valid access token in the header. I added to all my AJAX requests the header with the token:
$.ajaxSetup headers:
auth_token: auth_token
In order to secure the image access, I wanted to use the same logic and add the token in the request header. Apparently, I can do that only with an AJAX request and Base64 image data:
$.get url, (imageData) =>
$image.attr src: "data:image/jpeg;base64," + imageData
I'm not sure about the performance? Because my images size are between 12 bytes and 4mb and also, I want full mobile support.
The other way I found is with queries string:
$image.attr src: 'image/12.jpg?auth_token=' + token
It's working great, except the fact that my image won't be cached when the token changes.
What options are left?