Skip to content

Commit

Permalink
feat(pwa): enable SW file caching
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Nov 6, 2024
1 parent d0db6ba commit 08ac653
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion includes/class-newspack.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ private function includes() {
include_once NEWSPACK_ABSPATH . 'includes/class-donations.php';
include_once NEWSPACK_ABSPATH . 'includes/class-category-pager.php';
include_once NEWSPACK_ABSPATH . 'includes/class-salesforce.php';
include_once NEWSPACK_ABSPATH . 'includes/class-pwa.php';
include_once NEWSPACK_ABSPATH . 'includes/class-starter-content.php';
include_once NEWSPACK_ABSPATH . 'includes/class-amp-enhancements.php';
include_once NEWSPACK_ABSPATH . 'includes/class-newspack-image-credits.php';
Expand All @@ -160,6 +159,7 @@ private function includes() {
include_once NEWSPACK_ABSPATH . 'includes/plugins/class-onesignal.php';
include_once NEWSPACK_ABSPATH . 'includes/plugins/class-organic-profile-block.php';
include_once NEWSPACK_ABSPATH . 'includes/plugins/class-perfmatters.php';
include_once NEWSPACK_ABSPATH . 'includes/plugins/class-pwa.php';
include_once NEWSPACK_ABSPATH . 'includes/plugins/co-authors-plus/class-guest-contributor-role.php';
include_once NEWSPACK_ABSPATH . 'includes/plugins/co-authors-plus/class-search-authors-limit.php';
include_once NEWSPACK_ABSPATH . 'includes/plugins/wc-memberships/class-memberships.php';
Expand Down
10 changes: 9 additions & 1 deletion includes/class-pwa.php → includes/plugins/class-pwa.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ public static function init() {

add_action( 'wp_front_service_worker', [ __CLASS__, 'bypass_service_worker' ], 100 );
add_action( 'wp_admin_service_worker', [ __CLASS__, 'bypass_service_worker' ], 100 );

// Replace the SW caching header ('no-cache' by default), so it can be cached (for a day).
add_action(
'wp_front_service_worker',
function () {
header( 'Cache-Control: max-age=86400, must-revalidate' );
}
);
}

/**
Expand Down Expand Up @@ -107,7 +115,7 @@ public static function error_messages( $messages ) {

/**
* Temporary workaround to disable the offline post request handling script.
*
*
* @param WP_Service_Worker_Scripts $scripts The service worker scripts.
*
* @see - https://github.com/GoogleChromeLabs/pwa-wp/issues/1106
Expand Down

0 comments on commit 08ac653

Please sign in to comment.