Skip to content

Commit 8b9a3cd

Browse files
committed
Optimize the lazy-loading DPR numbers
1 parent 56c8ef2 commit 8b9a3cd

6 files changed

Lines changed: 21 additions & 4 deletions

File tree

js/inline-loader.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array(), 'version' => '2814799d655f563dcef8');
1+
<?php return array('dependencies' => array(), 'version' => '007ec7db37693c504126');

js/inline-loader.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/lazy-load.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array(), 'version' => 'ded1dd3da3fe93cb64da');
1+
<?php return array('dependencies' => array(), 'version' => '55e7765755171c4d412c');

js/lazy-load.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/inline-loader.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,20 @@ const CloudinaryLoader = {
151151
return 1;
152152
}
153153
let deviceDensity = this.deviceDensity;
154+
155+
// Round to nearest 0.5 to reduce URL variations
156+
if ( 'auto' !== deviceDensity ) {
157+
deviceDensity = Math.round( deviceDensity * 2 ) / 2;
158+
}
159+
154160
if (
155161
'max' !== maxDensity &&
156162
'auto' !== deviceDensity
157163
) {
158164
maxDensity = parseFloat( maxDensity );
165+
166+
// Round maxDensity to nearest 0.5 to maintain consistency
167+
maxDensity = Math.round( maxDensity * 2 ) / 2;
159168
deviceDensity =
160169
deviceDensity > Math.ceil( maxDensity )
161170
? maxDensity

src/js/lazy-load.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,19 @@ const LazyLoad = {
7373
return 1;
7474
}
7575
let deviceDensity = this.deviceDensity;
76+
77+
// Round to nearest 0.5 to reduce URL variations
78+
if ( 'auto' !== deviceDensity ) {
79+
deviceDensity = Math.round( deviceDensity * 2 ) / 2;
80+
}
81+
7682
if (
7783
'max' !== maxDensity &&
7884
'auto' !== deviceDensity
7985
) {
8086
maxDensity = parseFloat( maxDensity );
87+
// Round maxDensity to nearest 0.5 to maintain consistency
88+
maxDensity = Math.round( maxDensity * 2 ) / 2;
8189
deviceDensity =
8290
deviceDensity > Math.ceil( maxDensity )
8391
? maxDensity

0 commit comments

Comments
 (0)