OpenLayers HIDPI often causes GeoServer cache to fail.
Turning on HIDPI changes the way OpenLayer requests tiles etc.
You can specify diffrent dpi:s in geoserver, 90, 180 etc. But OpenLayers requests the exact dpi as the device has, for example 72, 113, 155, 189 etc etc. Confirmed in docs: HiDPI >
Use the ol/Map#pixelRatio value when requesting the image from the remote server.
If you're lucky, it requests 180 as it's set up in GeoServer.
For example, OpenLayers adds this to the Url:
WIDTH=538
HEIGHT=538
FORMAT_OPTIONS=dpi:189
Resulting in this header from geoserver:
geowebcache-cache-result: MISS
=== slow
Could we somehow force OpenLayers to request (as an example)?:
FORMAT_OPTIONS=dpi:90
WIDTH=256
HEIGHT=256
or double resolution for hidpi devices:
FORMAT_OPTIONS=dpi:180
WIDTH=512
HEIGHT=512
Everyone wants fast maps and sharp "crisp" maps. It would be nice to be able to deliver both.
Spontaneous thought: Combine custom imageLoadFunction (or similar) with window.devicePixelRatio
Quick test: Turned off HiDPI and Forced 180dpi 512x512 using tileLoadFunction on the left. (Chrome device emulator).

I think the idea of forcing specific DPI:s is good! Would 90 and 180 be enough (one for ordinary devices and one for highDPI-devices)? Or do we want more?
Maybe it could be configured like (devicePixelRatio: dpi):
{ "1.0": 90, "2.0": 180, }
Ahh very nice! I like it!
POC https://github.com/hajkmap/Hajk/tree/feature/915-custom-hdpi
The code looks great, nicely commented and easy to understand. Will give it a go next week!
Thanx! Don't forget to add useCustomHdpi: true in the layers config. I just noticed I forgot the first 'I' in hidpi :)
@jesade-vbg: Note: dpi can't be float, round up.
Added this to wms layer admin

Problems occur when having pixelRatio 3. ratio 1 and 2 seems to be working fine but 3 causes cache MISS in geoserver. geowebcache-cache-result:MISS geowebcache-miss-reason:request does not align to grid(s)
This also happens with the hidpi = true setting when requesting pixelRatio 3 270dpi, so its not my code.
I've found out that alot of people is having the exact same problem with openlayers + geoserver + pixelRatio 3. Feels like a rounding error. Still investigating........
If anyone has any idea, please let me know.