@@ -92,12 +92,7 @@ function amp_init() {
9292 */
9393 do_action ( 'amp_init ' );
9494
95- global $ amp_service_worker ;
96- $ amp_service_worker = new AMP_Service_Worker ();
97- $ amp_service_worker ->init ();
98-
9995 add_filter ( 'allowed_redirect_hosts ' , [ 'AMP_HTTP ' , 'filter_allowed_redirect_hosts ' ] );
100- add_filter ( 'wp_redirect ' , [ 'AMP_HTTP ' , 'add_purged_query_vars ' ] );
10196 AMP_HTTP ::purge_amp_query_vars ();
10297 AMP_HTTP ::send_cors_headers ();
10398 AMP_HTTP ::handle_xhr_request ();
@@ -527,7 +522,6 @@ function _amp_bootstrap_customizer() {
527522 * Redirects the old AMP URL to the new AMP URL.
528523 *
529524 * If post slug is updated the amp page with old post slug will be redirected to the updated url.
530- * Also includes all original query vars.
531525 *
532526 * @since 0.5
533527 *
@@ -794,7 +788,7 @@ function is_amp_endpoint() {
794788 (
795789 isset ( $ support_args ['app_shell ' ] )
796790 &&
797- 'inner ' === AMP_Theme_Support ::get_requested_app_shell_component ()
791+ 'inner ' === AMP_App_Shell ::get_requested_app_shell_component ()
798792 )
799793 );
800794
@@ -922,6 +916,13 @@ function amp_register_default_scripts( $wp_scripts ) {
922916 [],
923917 null
924918 );
919+ $ wp_scripts ->add_data (
920+ $ handle ,
921+ 'amp_script_attributes ' ,
922+ [
923+ 'async ' => true ,
924+ ]
925+ );
925926
926927 // Shadow AMP API.
927928 $ handle = 'amp-shadow ' ;
@@ -932,38 +933,6 @@ function amp_register_default_scripts( $wp_scripts ) {
932933 null
933934 );
934935
935- // Add Web Components polyfill if Shadow DOM is not natively available.
936- $ wp_scripts ->add_inline_script (
937- $ handle ,
938- sprintf (
939- 'if ( ! Element.prototype.attachShadow ) { const script = document.createElement( "script" ); script.src = %s; script.async = true; document.head.appendChild( script ); } ' ,
940- wp_json_encode ( 'https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/2.4.1/webcomponents-bundle.js ' )
941- ),
942- 'after '
943- );
944-
945- // App shell library.
946- $ handle = 'amp-wp-app-shell ' ;
947- $ asset_file = AMP__DIR__ . '/assets/js/ ' . $ handle . '.asset.php ' ;
948- $ asset = require $ asset_file ;
949- $ dependencies = $ asset ['dependencies ' ];
950- $ dependencies [] = 'amp-shadow ' ;
951- $ version = $ asset ['version ' ];
952- $ wp_scripts ->add (
953- $ handle ,
954- amp_get_asset_url ( 'js/ ' . $ handle . '.js ' ),
955- $ dependencies ,
956- $ version
957- );
958- $ wp_scripts ->add_data (
959- $ handle ,
960- 'amp_script_attributes ' ,
961- [
962- 'async ' => true ,
963- ]
964- );
965- $ wp_scripts ->add_data ( $ handle , 'precache ' , true );
966-
967936 // Register all AMP components as defined in the spec.
968937 foreach ( AMP_Allowed_Tags_Generated::get_extension_specs () as $ extension_name => $ extension_spec ) {
969938 $ src = sprintf (
@@ -1066,17 +1035,18 @@ function amp_render_scripts( $scripts ) {
10661035function amp_filter_script_loader_tag ( $ tag , $ handle ) {
10671036 $ prefix = 'https://cdn.ampproject.org/ ' ;
10681037 $ src = wp_scripts ()->registered [ $ handle ]->src ;
1069- $ attributes = wp_scripts ()->get_data ( $ handle , 'amp_script_attributes ' );
1070- if ( empty ( $ attributes ) && 0 === strpos ( $ src , $ prefix ) ) {
1071- // All scripts from AMP CDN should be loaded async.
1072- $ attributes = [
1073- 'async ' => true ,
1074- ];
1075- }
1076- if ( empty ( $ attributes ) ) {
1038+ if ( 0 !== strpos ( $ src , $ prefix ) ) {
10771039 return $ tag ;
10781040 }
10791041
1042+ /*
1043+ * All scripts from AMP CDN should be loaded async.
1044+ * See <https://www.ampproject.org/docs/integration/pwa-amp/amp-in-pwa#include-"shadow-amp"-in-your-progressive-web-app>.
1045+ */
1046+ $ attributes = [
1047+ 'async ' => true ,
1048+ ];
1049+
10801050 // Add custom-template and custom-element attributes. All component scripts look like https://cdn.ampproject.org/v0/:name-:version.js.
10811051 if ( 'v0 ' === strtok ( substr ( $ src , strlen ( $ prefix ) ), '/ ' ) ) {
10821052 /*
@@ -1779,63 +1749,6 @@ function amp_wp_kses_mustache( $markup ) {
17791749 return wp_kses ( $ markup , array_fill_keys ( $ amp_mustache_allowed_html_tags , [] ) );
17801750}
17811751
1782- /**
1783- * Mark the beginning of the content that will be displayed inside the app shell.
1784- *
1785- * Depends on adding app_shell to the amp theme support args.
1786- *
1787- * @since 1.1
1788- * @todo Should this take an argument for the content placeholder?
1789- */
1790- function amp_start_app_shell_content () {
1791- $ support_args = AMP_Theme_Support::get_theme_support_args ();
1792- if ( ! isset ( $ support_args ['app_shell ' ] ) ) {
1793- return ;
1794- }
1795-
1796- printf ( '<div id="%s"> ' , esc_attr ( AMP_Theme_Support::APP_SHELL_CONTENT_ELEMENT_ID ) );
1797-
1798- // Start output buffering if requesting outer shell, since all content will be omitted from the response.
1799- if ( 'outer ' === AMP_Theme_Support::get_requested_app_shell_component () ) {
1800- $ content_placeholder = '<p> ' . esc_html__ ( 'Loading… ' , 'amp ' ) . '</p> ' ;
1801-
1802- /**
1803- * Filters the content which is shown in the app shell for the content before it is loaded.
1804- *
1805- * This is used to display a loading message or a content skeleton.
1806- *
1807- * @since 1.1
1808- * @todo Consider using template part for this instead, or an action with a default.
1809- *
1810- * @param string $content_placeholder Content placeholder.
1811- */
1812- echo apply_filters ( 'amp_app_shell_content_placeholder ' , $ content_placeholder ); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
1813-
1814- ob_start ();
1815- }
1816- }
1817-
1818- /**
1819- * Mark the end of the content that will be displayed inside the app shell.
1820- *
1821- * Depends on adding app_shell to the amp theme support args.
1822- *
1823- * @since 1.1
1824- */
1825- function amp_end_app_shell_content () {
1826- $ support_args = AMP_Theme_Support::get_theme_support_args ();
1827- if ( ! isset ( $ support_args ['app_shell ' ] ) ) {
1828- return ;
1829- }
1830-
1831- // Clean output buffer if requesting outer shell, since all content will be omitted from the response.
1832- if ( 'outer ' === AMP_Theme_Support::get_requested_app_shell_component () ) {
1833- ob_end_clean ();
1834- }
1835-
1836- printf ( '</div><!-- #%s --> ' , esc_attr ( AMP_Theme_Support::APP_SHELL_CONTENT_ELEMENT_ID ) );
1837- }
1838-
18391752/**
18401753 * Add "View AMP" admin bar item for Transitional/Reader mode.
18411754 *
0 commit comments