Follows-up T422586: MediaViewer downloads high-res image twice if original is a medium-size JPEG.
It still downloads images twice when the thumb size ends up used as the high-res version (i.e. mobile screen, narrow desktop window, or if original is not very big).
I narrowed down the cause to a difference in CORS mode, as indicated here by Sec-Fetch-Mode: cors and Sec-Fetch-Mode: no-cors differing.
| Prod | ||
|---|---|---|
| Local | ||
This is implemented in mmv.provider.Image.js as follows:
rawGet( url, cors ) { const img = new window.Image(); // This attribute is necessary in Firefox, which needs it for the image request after // the XHR to hit the cache by being a proper CORS request. if ( cors ) { img.crossOrigin = 'anonymous'; }
I'm guessing this was created with an expectation that it is uncommon for a thumbnail to be suitable as the high-res preview. And so the fact that enabling CORS prevents re-use of browser cache for a regular <img> without this attribute (such as the thumbnail we clicked), was probably considered unimportant and worth the compromise in order to get the XHR feature working.
This XHR feature existed in order to get xhr.onprogress events to use for a progress bar. @simon04 recently mentioned this wasn't used in practice, because we dispay the low-res image as placeholder instead of a progress bar. The remnant code for this was removed in change 1281972.
So.. we if we get rid of this condition, we should be able to enjoy full cache re-use.



