3

I am using signed urls for images but also would like them to be responsive. Do I really need to sign all size versions of the picture? It seems more efficient if first the actual size that will be shown is determined so I only need to provide a signed url for that image. Is there a common approach for this?

So e.g. this html:

<img srcset="elva-fairy-320w.jpg 320w,
             elva-fairy-480w.jpg 480w,
             elva-fairy-800w.jpg 800w"
     sizes="(max-width: 320px) 280px,
            (max-width: 480px) 440px,
            800px"
     src="elva-fairy-800w.jpg" alt="Elva dressed as a fairy">

Would I need to sign all elva-fairy urls in the srcset?

musicformellons
  • 12,283
  • 4
  • 51
  • 86

1 Answers1

3

Yes, you will need a different signed URL for each unique image. Signed URLs don't automatically resize or redirect to other objects in your storage bucket.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Well that's a nice concise answer, thanks. As the actual signing is done on my server with an encryption calculation (so not an api request towards Google), it will be a five-fold (different sizes) calculation now. Is this something to worry about, or are these calculations 'negligible' from a performance point of view...? – musicformellons Jun 12 '19 at 16:27
  • Actually, it would also be handy to have an event on the `img` element that gives the actual 'chosen src' before it starts loading it. That does not exist? – musicformellons Jun 12 '19 at 16:30
  • Signed URLs are generated by Cloud Storage, You simply invoke an API to generate one. – Doug Stevenson Jun 12 '19 at 16:39
  • As stated before it is not in my case as I am using the [Algorithm for signing](https://cloud.google.com/storage/docs/access-control/signing-urls-manually#algorithm) URLs on my own server. – musicformellons Jun 12 '19 at 16:49
  • It sounds like should benchmark your own code then. – Doug Stevenson Jun 12 '19 at 16:59
  • Yeah, will try and see what happens. – musicformellons Jun 12 '19 at 20:04