Skip to content

Commit

Permalink
Create plugin support for CDN'ing of static assets. (#10102)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
George Stephanis authored Sep 19, 2018
1 parent 8b7e85a commit e4c2786
Show file tree
Hide file tree
Showing 6 changed files with 1,130 additions and 351 deletions.
20 changes: 20 additions & 0 deletions bin/build-asset-cdn-json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

$path = dirname( dirname( __FILE__ ) ) . '/';
$directory = new RecursiveDirectoryIterator( $path );
$iterator = new RecursiveIteratorIterator( $directory );
$regex = new RegexIterator( $iterator, '/^.+\.(css|js)$/i', RecursiveRegexIterator::GET_MATCH );

$manifest = array();
foreach ( $regex as $file => $value ) {
$file = str_replace( $path, '', $file );
$directory = substr( $file, 0, strpos( $file, '/' ) );
if ( in_array( $directory, array( 'node_modules', 'tests' ) ) ) {
continue;
}
$manifest[] = $file;
}

$export = var_export( $manifest, true );

file_put_contents( $path . 'modules/photon-cdn/jetpack-manifest.php', "<?php \r\n\$assets = $export;\r\n" );
1 change: 1 addition & 0 deletions class.jetpack-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static function get_option_names( $type = 'compact' ) {
'dismissed_connection_banner', // (bool) True if the connection banner has been dismissed
'onboarding', // (string) Auth token to be used in the onboarding connection flow
'tos_agreed', // (bool) Whether or not the TOS for connection has been agreed upon.
'static_asset_cdn_files', // (array) An nested array of files that we can swap out for cdn versions.
);

case 'private' :
Expand Down
Loading

0 comments on commit e4c2786

Please sign in to comment.