posts: use low quality thumbnails when Save-Data header is set.

When the Save-Data HTTP header is present, disable high quality (2x
pixel density) thumbnails. This is normally set when "Data Saver mode"
is enabled on Android, or "Lite mode" is enabled in Chrome.

This setting can also be set using the `save_data` URL param or HTTP
cookie. This is mainly for testing.

The <body> tag has a `current-user-save-data` data attribute that
indicates whether save data mode is on.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Save-Data
https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/save-data/#the_save-data_request_header
https://source.android.com/devices/tech/connect/data-saver
This commit is contained in:
evazion
2021-12-09 19:52:02 -06:00
parent 7dbde7bc14
commit 52013eac1f
5 changed files with 28 additions and 13 deletions

View File

@@ -252,7 +252,7 @@ module ApplicationHelper
render "table_builder/table", table: table
end
def body_attributes(user, params, current_item = nil)
def body_attributes(current_user, params, current_item = nil)
controller_param = params[:controller].parameterize.dasherize
action_param = params[:action].parameterize.dasherize
@@ -265,7 +265,8 @@ module ApplicationHelper
action: action_param,
layout: controller.class.send(:_layout),
"current-user-ip-addr": request.remote_ip,
**current_user_data_attributes(user),
"current-user-save-data": CurrentUser.save_data,
**current_user_data_attributes(current_user),
**cookie_data_attributes,
**current_item_data_attributes(current_item),
}