Skip to content

Conversation

@kasparsd
Copy link
Contributor

Fixes #1850 #820

Changes proposed in this Pull Request:

  • Enqueue https://s0.wp.com/wp-content/js/devicepx-jetpack.js only if the theme defines support for it via add_theme_support( 'jetpack-devicepx' ).

  • Set jetpack-devicepx as not supported during AMP requests.

Testing instructions:

  • Enable the Jetpack plugin. It no longer enqueues the https://s0.wp.com/wp-content/js/devicepx-jetpack.js script on all pages automatically.

  • Add add_theme_support( 'jetpack-devicepx' ); to theme's functions.php and notice that now all front-end page loads include the https://s0.wp.com/wp-content/js/devicepx-jetpack.js script.

  • Load an AMP page and notice that the devicepx library is not loaded as expected.

Proposed changelog entry for your changes:

Disable the devicepx library by default and allow themes to enable it via the add_theme_support( 'jetpack-devicepx' ); toggle.

@kasparsd kasparsd requested a review from a team as a code owner September 20, 2018 11:15
@kasparsd kasparsd changed the title Make devicepx library a theme feature Make devicepx library an optional theme feature Sep 20, 2018
@jetpackbot
Copy link
Collaborator

jetpackbot commented Sep 20, 2018

That's a great PR description, thank you so much for your effort!

Generated by 🚫 dangerJS

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. If we make devicepx a tool that can be activated in your theme, it may be useful to move it with the other theme tools in Jetpack, in its own file here:
https://github.com/Automattic/jetpack/tree/master/modules/theme-tools

Here is where those tools are loaded:
https://github.com/Automattic/jetpack/blob/master/modules/module-extras.php#L8

You could then check for Jetpack::is_active() at the top of that new file, and also check for current_theme_supports( 'jetpack-devicepx' ) there. You could even check for AMP there, as we do here for example:

! Jetpack_AMP_Support::is_amp_request();

@kasparsd
Copy link
Contributor Author

If we make devicepx a tool that can be activated in your theme, it may be useful to move it with the other theme tools in Jetpack

@jeherve Makes sense. Do you suggest we add a checkbox to the settings or implement it as code-only option similar to content-options?

@jeherve
Copy link
Member

jeherve commented Sep 20, 2018

I don't think there should be any UI for it. All those theme tools are activated via code.

jeherve
jeherve previously approved these changes Sep 20, 2018
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of this small change?

@jeherve jeherve added [Status] Needs Review This PR is ready for review. and removed [Status] In Progress labels Sep 20, 2018
@kraftbj
Copy link
Contributor

kraftbj commented Sep 25, 2018

@josephscott With your history with devicepx, wanted to get a check from you for disabling it by default. Any reason we shouldn't? IIRC, when adding srcset support to Photon, our long-term goal was to remove the need for devicepx.

Copy link
Contributor Author

@kasparsd kasparsd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review @kraftbj -- comment added.

@josephscott
Copy link
Contributor

As a general item, I'd be happy to see devicepx go away entirely. My only concern is for places that assume it will be around and could potentially end up with unexpected results.

Devicepx came about because there were not great ways for managing alternate image needs, like DPI ( retina ). Now, we have much better options that don't require JavaScript to be checking things all the time. We certainly have the browser feature support that makes it possible for devicepx to go away.

# Conflicts:
#	3rd-party/class.jetpack-amp-support.php
#	class.jetpack.php
#	modules/module-extras.php
#	tests/php.multisite.xml
@jetpackbot
Copy link
Collaborator

jetpackbot commented Dec 19, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: January 14, 2020.
Scheduled code freeze: January 7, 2020

Generated by 🚫 dangerJS against fc797d3

@kasparsd
Copy link
Contributor Author

@brbrr The unit tests have been fixed. Previously it was expecting the devicepx script to be enqueued even though the wp_enqueue_scripts hooks hadn't been called, yet. We're now checking for the presence of the hooked callback instead.

@jeherve This is now ready at its simplest form. Let me know if anything else is needed to get this past the finish line. Thank you!

@jeherve jeherve added this to the 8.1 milestone Dec 19, 2019
@jeherve jeherve added [Status] Needs Review This PR is ready for review. [Pri] Low and removed [Status] In Progress labels Dec 19, 2019
Copy link
Contributor

@brbrr brbrr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason, I was not able to load devicepx after adding it into TwentyTwenty functions.php. Also tested with other themes and AMP active/deactive.

Any ideas what I might be doing wrong?

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello kasparsd! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D37141-code before merging this PR. Thank you!

Copy link
Contributor

@zinigor zinigor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well in my tests, I have been able to add the enqueued script by using this snippet:

add_action( 'init', 'zinigor_declare_theme_support' );
function zinigor_declare_theme_support() {
	add_theme_support( 'jetpack-devicepx' );
}

Thanks!

@zinigor zinigor added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Dec 27, 2019
@zinigor zinigor dismissed brbrr’s stale review December 30, 2019 17:19

Travis is now fine, thanks for the review!

@zinigor zinigor merged commit 2b73892 into Automattic:master Dec 30, 2019
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Dec 30, 2019
zinigor added a commit that referenced this pull request Dec 30, 2019
zinigor added a commit that referenced this pull request Dec 30, 2019
* Changelog: 8.1 additions

* Changelog: add #13858

* Changelog: add #13963

* Changelog: add #14174

* Changelog: add #14178

* Changelog: add #14175

* Changelog: add #14192

* Changelog: add #14196

* Changelog: add #14182

* Changelog: add #14218

* Changelog: add #14214

* Changelog: add #13757

* Changelog: add #14190

* Changelog: add #14131

* Changelog: add #14101

* Changelog: add #14203

* Changelog: add #14211

* Changelog: add #14224

* Changelog: add #14230

* Changelog: add #14241

* Changelog: add #14249

* Changelog: add #14264

* Changelog: add #14263

* Changelog: add #14256

* Changelog: add #10189

* Changelog: add #14240

* Changelog: add #14239

Also added some new entries to the testing file.

Co-authored-by: Igor Zinovyev <[email protected]>
zinigor added a commit that referenced this pull request Dec 30, 2019
* Changelog: 8.1 additions

* Changelog: add #13858

* Changelog: add #13963

* Changelog: add #14174

* Changelog: add #14178

* Changelog: add #14175

* Changelog: add #14192

* Changelog: add #14196

* Changelog: add #14182

* Changelog: add #14218

* Changelog: add #14214

* Changelog: add #13757

* Changelog: add #14190

* Changelog: add #14131

* Changelog: add #14101

* Changelog: add #14203

* Changelog: add #14211

* Changelog: add #14224

* Changelog: add #14230

* Changelog: add #14241

* Changelog: add #14249

* Changelog: add #14264

* Changelog: add #14263

* Changelog: add #14256

* Changelog: add #10189

* Changelog: add #14240

* Changelog: add #14239

Also added some new entries to the testing file.

Co-authored-by: Igor Zinovyev <[email protected]>
@kasparsd kasparsd deleted the fix/1850-devicepx branch January 8, 2020 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Devicepx: add it as a module or a theme tool to avoid confusion

8 participants