-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create plugin support for CDN'ing of static assets. #10102
Conversation
plugin files only for now
If it is a development version, we want to use local up to date assets.
That's a great PR description, thank you so much for your effort! Generated by 🚫 dangerJS |
We shouldn't need versino numbers as the core version is in the path.
Make it easier to do WooCommerce and others as well.
I'm unsure if it may be wiser to change how we swap the urls and such to a just in time based off a later filter or action. |
I'm probably okay skipping exceptions for the emoji ones for the moment -- I don't want the initial PR to be too epically complex. Good catch on Akismet -- I think that's because it's coming back with the core hashes, as it's bundled in the zip -- but not getting pulled over by @bazza's cdn. Not a big deal, I'll just prune them from what gets rewritten. Talking to @claudiulodro about WooCommerce in Slack currently, seeing when we can get WC core onboard. They're currently past feature freeze, so it'll need to probably be for 3.6 |
This will break the CDN'ing of scripts, and as they're being served over HTTP/2 concatenation provides less benefit over the ability of the browser to cache individual assets.
Up until now, no rtl files or min files were generated when running `yarn build`. This caused issues on RTL sites, but also in other places where we look for the file, like in the work we are doing in #10102
Instead of hitting the API and related overhead, let's just assume that if Core is a publicly released version (no `-dev` or `-rc2` versions or the like) that the tag will be in the CDN, and then rewrite any css/js files in the `wp-includes` and `wp-admin` directories.
@georgestephanis sorry, there seems to be a problem with your latest change. It looks like Jetpack, and maybe some other plugins as well, enqueue assets with URLs like this: We're going to be breaking these for all plugins that rely on that mechanism. We could probably blacklist URLs that have |
Ahhh shucks. Okay. Good find, I'll add a check. |
Caution: This PR has changes that must be merged to WordPress.com |
That should have it fixed, @zinigor |
Tested, fixes the problem, thank you! And huge props for @dereksmart for finding the problem! |
I tested the PR one more time, and did not run into any major issues. It works well. One quick note is that you can't really test this when using the Lazy Images feature; since we've modified Lazy Images in the past few weeks, the .js file served from the CDN is not compatible with the current development version of Jetpack. |
Once it's launchable, I'd like to switch it to only cdn on public versions of the codebase. Should remedy that issue, but possibly make it harder to test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Let's test it for real now! 🚢
* Add in support for `integrity` data for SRI. * esc_attr ftw * Add populating for integrity parameters based on .org api plugin files only for now * Correct the conditionals for the right error condition. * Only swap out Jetpack asset urls if it's not a development version. If it is a development version, we want to use local up to date assets. * Tidy up the actions that it runs on * Abstract some stuff like versions out * Styles need love too * Skip for already done items * Add ability to pass in plugin and versino for getting checksums * Add ability to get known plugin versions. * Whitespace * Move line * Retool get core checksums to take args * First pass at swapping out core files * Oops. Forgot to specify the proper item in the object. * Add a better fallback and remove an instance that shouldn't happen. * Some additional docs and tidying. * Switch url pattern for cdn as per @bazza * Ditch version numbers We shouldn't need versino numbers as the core version is in the path. * Abstract out the plugin resource swapping. Make it easier to do WooCommerce and others as well. * Purge SRI validation for the moment. Wins from it are incremental, and we'll probably re-add it later -- but with better sourcing for the hashes. * Somewhat big overhaul. * Stop caring about hashes, just care about files. * Add in caching of the file manifest based on plugin / core versions * Strip down how much data we're stashing * Use array_filter for more intelligible code than a foreach * ??? * PROFIT! * Fixed a fatal and a warning. * Moved the CDN class to its own module to be able to turn it off and on. * Simplify how we get the core checksums. * Extract out the cdn domain to a class constant. * Short circuit fn if no data returned. * Don't loop through core files if there isn't a cdn'd version. * Undo whitespace tweaks for less churn * tabs > spaces * Revert whitespace change for cleaner pr * If querying for the current version of Jetpack, return the built manifest. * Added override filters for plugin and core version strings. * Added a line to generate the manifest as the latest stage before deploying to SVN. * Add new method for testing if a version number is public and can be on t he cdn. * Deactivate requiring a connection for now. Helps with local testing, but we may need it on for shipping, just for TOS purposes. * Fixed filter name, props @georgestephanis. * Added the core asset version filter where it needed to be. * Removed an unneeded excludes definition and fixed whitespace. * Whitespace, comments and lint pass. * Also swap to cdn versions on the admin side. Props @jeherve for the catch. * Only query the api if the version string looks like a public release. * Let other plugins return their assets via a filter, rather than an external api or stored option. * Cache for up to 24h the lack of data about a specific plugin version. * Add support for CDN'ing WooCommerce assets as well. * Make sure wp-admin isn't concatenating scripts. This will break the CDN'ing of scripts, and as they're being served over HTTP/2 concatenation provides less benefit over the ability of the browser to cache individual assets. * Simplify the rewriting of Core assets. Instead of hitting the API and related overhead, let's just assume that if Core is a publicly released version (no `-dev` or `-rc2` versions or the like) that the tag will be in the CDN, and then rewrite any css/js files in the `wp-includes` and `wp-admin` directories. * Make sure we're not rewriting odd stuff like using admin-ajax to serve scripts
When the static asset CDN of Jetpack is loaded, the translations for Gutenberg don'tt load properly because the filename is generated for a wrong path. Also fixes Automattic/wp-calypso#29309 This has been extensively discussed in https://core.trac.wordpress.org/ticket/45528 #### Changes proposed in this Pull Request: * This implements the filter that has been introduced into Core. #### Testing instructions: Prequisit: WordPress 5.0.2(alpha) or trunk 1. Set your WordPress to another language than English. 2. Activate Jetpack Static Asset CDN. 3. Potentially add a filter to your WordPress if it's running trunk (see #10102) 4. Create a new post to open Gutenberg and observe broken translations. 5. Activate the patch: Translations should now load after a reload. #### Proposed changelog entry for your changes: * Fixes loading of the Block Editor UI translations when Static Asset CDN is used (requires WordPress 5.0.2)
Add in CDN hosted versions of Core / Jetpack scripts and styles to speed up sites and better cross-site cacheability.
To do:
Testing instructions:
Proposed changelog entry for your changes: