From 828f6d6ac9db63bd5ac56f6d7470f4568d6ec09d Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sun, 24 Jun 2018 00:30:18 +0100 Subject: [PATCH] skins: Remove redundant mediawiki.hidpi script This is an internal script automatically loaded by Skin.php to activate the 'jquery.hidpi' polyfill for all images on the current page in browsers that don't natively support the 'srcset' attribute on the HTML img element. This script is loaded via ResourceLoader for which Grade A currently requires: > IE11+/Edge, Chr 65+, Ff 52+, Saf 5+, Op 15+, iOS 6+, Android 4+. According to MDN and CanIUse, the basic 'x' syntax of srcset is supported, and enabled by default, in: > Edge, Chr 34+, Ff 38+, Saf 7+, Op 21+, iOS 8+, Android 5+. This means in the following browsers, MediaWiki will no longer attempt to replace images in articles with their hidpi versions. | Browser | analytics.wikimedia.org (22 May - 22 June) | ---------------------- | ----------------------- | IE 11 on Windows <= 7 | 3.4% (OS does not support HiDPI) | IE 11 on Windows 8+ | 1.1% | Safari 5 & 6 (desktop) | <0.1% | Opera 15-20 (desktop) | <0.1% | iOS 6 & 7 (mobile) | 0.1% | Android 4 (mobile) | 0.5% While the total of 1.7% is higher than our usual point where we decide to remove support, I think we should consider dropping the hidpi polyfill still for several reasons: * MobileFrontend no longer uses 'srcset' attributes. As such, these browsers don't actually change their behaviour based on the polyfill. * For IE 11/Win8 in particular, most users don't have an HiDPI monitor, but we still download the polyfill. HiDPI on Win8 is primarily tablets. * In all cases where the polyfill activates, we download the HiDPI images in addition to the standard resolution (which downloads and renders first). This is because client-side JavaScript is not able to replace it sooner. This could be considered a waste of bandwidth, as it can double or tripple the bandwidth cost for end users. This also means pages complete their loading much later because the browser first renders the page nearly to completion with standard resolution images, and only at the end our polyfill activates to restarts all image loading. The experience gracefully falls back to normal web rendering, where the standard resolution of the image is used. This would match what users of these devices see on other websites, given client-side emulation of srcset is fairly rare. == Modules The 'mediawiki.hidpi' module was removed, and considered internal to Skin.php. It contained no public methods. I confirmed there were no matches in Codesearch, and no matches in mwgrep on Wikimedia wikis. I did not remove 'jquery.hidpi', which is what contains the actual polyfill and the jQuery.fn.hidpi() public method. (Codesearch shows 2 extenisons using it, and mwgrep returned 1 unused gadget on Meta-Wiki referencing it). It has been kept, but marked as deprecated. To be removed in a future release. Bug: T127328 Change-Id: I42ce0feea1fbfe534f00e05a7cd8d81df0c33d8f --- Gruntfile.js | 4 +--- RELEASE-NOTES-1.32 | 1 + includes/DefaultSettings.php | 4 ---- includes/skins/Skin.php | 5 ----- resources/Resources.php | 7 +------ resources/src/mediawiki.hidpi/hidpi.js | 5 ----- resources/src/mediawiki.hidpi/skip.js | 4 ---- 7 files changed, 3 insertions(+), 27 deletions(-) delete mode 100644 resources/src/mediawiki.hidpi/hidpi.js delete mode 100644 resources/src/mediawiki.hidpi/skip.js diff --git a/Gruntfile.js b/Gruntfile.js index 8018212e85..6be908e087 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -33,9 +33,7 @@ module.exports = function ( grunt ) { '!vendor/**', // Explicitly say "**/*.js" here in case of symlinks '!extensions/**/*.js', - '!skins/**/*.js', - // Skip functions aren't even parseable - '!resources/src/mediawiki.hidpi/skip.js' + '!skins/**/*.js' ] }, jsonlint: { diff --git a/RELEASE-NOTES-1.32 b/RELEASE-NOTES-1.32 index c4a8fefd40..3c60124d40 100644 --- a/RELEASE-NOTES-1.32 +++ b/RELEASE-NOTES-1.32 @@ -218,6 +218,7 @@ because of Phabricator reports. * (T176526) EditPage::getContextTitle() falling back to $wgTitle when the context title is unset is now deprecated; anything creating an EditPage instance should set the context title via ::setContextTitle(). +* The 'jquery.hidpi' module (polyfill for IMG srcset) is deprecated. === Other changes in 1.32 === * … diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 2c9828385b..8b256724dd 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1500,10 +1500,6 @@ $wgDirectoryMode = 0777; * * This means a 320x240 use of an image on the wiki will also generate 480x360 and 640x480 * thumbnails, output via the srcset attribute. - * - * On older browsers, a JavaScript polyfill switches the appropriate images in after loading - * the original low-resolution versions depending on the reported window.devicePixelRatio. - * The polyfill can be found in the jquery.hidpi module. */ $wgResponsiveImages = true; diff --git a/includes/skins/Skin.php b/includes/skins/Skin.php index 8384ca0c25..51be3b6551 100644 --- a/includes/skins/Skin.php +++ b/includes/skins/Skin.php @@ -212,11 +212,6 @@ abstract class Skin extends ContextSource { 'syndicate' => [], ]; - // Support for high-density display images if enabled - if ( $config->get( 'ResponsiveImages' ) ) { - $modules['core'][] = 'mediawiki.hidpi'; - } - // Preload jquery.tablesorter for mediawiki.page.ready if ( strpos( $out->getHTML(), 'sortable' ) !== false ) { $modules['content'][] = 'jquery.tablesorter'; diff --git a/resources/Resources.php b/resources/Resources.php index 1b6eed30a9..44b028d86e 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -228,6 +228,7 @@ return [ 'targets' => [ 'desktop', 'mobile' ], ], 'jquery.hidpi' => [ + 'deprecated' => 'Use of the srcset polyfill is deprecated since MediaWiki 1.32.0', 'scripts' => 'resources/src/jquery/jquery.hidpi.js', 'targets' => [ 'desktop', 'mobile' ], ], @@ -1051,12 +1052,6 @@ return [ ], 'targets' => [ 'desktop', 'mobile' ], ], - 'mediawiki.hidpi' => [ - 'scripts' => 'resources/src/mediawiki.hidpi/hidpi.js', - 'dependencies' => 'jquery.hidpi', - 'skipFunction' => 'resources/src/mediawiki.hidpi/skip.js', - 'targets' => [ 'desktop', 'mobile' ], - ], 'mediawiki.hlist' => [ 'targets' => [ 'desktop', 'mobile' ], 'styles' => [ diff --git a/resources/src/mediawiki.hidpi/hidpi.js b/resources/src/mediawiki.hidpi/hidpi.js deleted file mode 100644 index ecee450c85..0000000000 --- a/resources/src/mediawiki.hidpi/hidpi.js +++ /dev/null @@ -1,5 +0,0 @@ -jQuery( function ( $ ) { - // Apply hidpi images on DOM-ready - // Some may have already partly preloaded at low resolution. - $( 'body' ).hidpi(); -} ); diff --git a/resources/src/mediawiki.hidpi/skip.js b/resources/src/mediawiki.hidpi/skip.js deleted file mode 100644 index 26b63c7b01..0000000000 --- a/resources/src/mediawiki.hidpi/skip.js +++ /dev/null @@ -1,4 +0,0 @@ -/*! - * Skip function for mediawiki.hdpi.js. - */ -return 'srcset' in new Image(); -- 2.20.1