Skip to content

Commit

Permalink
Provide cache even if ao_noptimize query string exists
Browse files Browse the repository at this point in the history
  • Loading branch information
GeekPress committed Mar 20, 2017
1 parent 6bc035c commit cdf17e8
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions inc/front/process.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
&& ( ! isset( $_GET['lang'] ) )
&& ( ! isset( $_GET['s'] ) )
&& ( ! isset( $_GET['age-verified'] ) )
&& ( ! isset( $_GET['ao_noptimize'] ) )
&& ( ! isset( $rocket_cache_query_strings ) || ! array_intersect( array_keys( $_GET ), $rocket_cache_query_strings ) )
) {
rocket_define_donotminify_constants( true );
Expand Down Expand Up @@ -156,9 +157,9 @@
$user_key = explode( '|', $_COOKIE[ 'wordpress_logged_in_' . $rocket_cookie_hash ] );
$user_key = reset( ( $user_key ) );
$user_key = $user_key . '-' . $rocket_secret_cache_key;

// Get cache folder of host name
$request_uri_path = $rocket_cache_path . $host . '-' . $user_key . rtrim( $request_uri, '/' );
$request_uri_path = $rocket_cache_path . $host . '-' . $user_key . rtrim( $request_uri, '/' );
}
}
else {
Expand All @@ -170,15 +171,15 @@
// Rename the caching filename for mobile
if ( isset( $rocket_cache_mobile, $rocket_do_caching_mobile_files ) && class_exists( 'Rocket_Mobile_Detect' ) ) {
$detect = new Rocket_Mobile_Detect();

if ( $detect->isMobile() && ! $detect->isTablet() ) {
$filename .= '-mobile';
}

if ( strpos( $_SERVER['SERVER_SOFTWARE'], 'nginx' ) !== false ) {
// Create a hidden empty file for mobile detection on NGINX with the Rocket NGINX configuration
$nginx_mobile_detect_file = $request_uri_path . '/.mobile-active';

if ( ! file_exists( $nginx_mobile_detect_file ) ) {
touch( $nginx_mobile_detect_file );
}
Expand All @@ -191,7 +192,7 @@
}

// Rename the caching filename depending to dynamic cookies
if ( ! empty( $rocket_cache_dynamic_cookies ) ) {
if ( ! empty( $rocket_cache_dynamic_cookies ) ) {
foreach( $rocket_cache_dynamic_cookies as $cookie_name ) {
if( ! empty( $_COOKIE[ $cookie_name ] ) ) {
$cache_key = $_COOKIE[ $cookie_name ];
Expand Down Expand Up @@ -225,7 +226,7 @@ function do_rocket_callback( $buffer ) {
* @param bool true will force caching search results
*/
$rocket_cache_search = apply_filters( 'rocket_cache_search', false );

/**
* Allow to override the DONOTCACHEPAGE behavior.
* To warn conflict with some plugins like Thrive Leads.
Expand All @@ -235,7 +236,7 @@ function do_rocket_callback( $buffer ) {
* @param bool true will force the override
*/
$rocket_override_donotcachepage = apply_filters( 'rocket_override_donotcachepage', false );

if ( strlen( $buffer ) > 255
&& ( function_exists( 'is_404' ) && ! is_404() ) // Don't cache 404
&& ( function_exists( 'is_search' ) && ! is_search() || $rocket_cache_search ) // Don't cache search results
Expand All @@ -246,7 +247,7 @@ function do_rocket_callback( $buffer ) {

$footprint = '';
$is_html = false;

if( preg_match( '/(<\/html>)/i', $buffer ) ) {
// This hook is used for:
// - Add width and height attributes on images
Expand All @@ -256,10 +257,10 @@ function do_rocket_callback( $buffer ) {
// - CDN
// - LazyLoad
$buffer = apply_filters( 'rocket_buffer', $buffer );

$is_html = true;
}

/**
* Allow to the generate the caching file
*
Expand All @@ -270,11 +271,11 @@ function do_rocket_callback( $buffer ) {
if ( apply_filters( 'do_rocket_generate_caching_files', true ) ) {
// Create cache folders of the request uri
rocket_mkdir_p( $request_uri_path );

if( $is_html ) {
$footprint = get_rocket_footprint();
}

// Save the cache file
rocket_put_content( $rocket_cache_filepath, $buffer . $footprint );

Expand All @@ -291,7 +292,7 @@ function do_rocket_callback( $buffer ) {
if( $is_html ) {
$footprint = get_rocket_footprint(false);
}

$buffer = $buffer . $footprint;
}

Expand All @@ -304,7 +305,7 @@ function do_rocket_callback( $buffer ) {
* @since 2.0
*/
function rocket_serve_cache_file( $rocket_cache_filepath ) {

// Check if cache file exist
if ( file_exists( $rocket_cache_filepath ) && is_readable( $rocket_cache_filepath ) ) {

Expand All @@ -322,7 +323,7 @@ function rocket_serve_cache_file( $rocket_cache_filepath ) {
header( $_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified', true, 304 );
exit;
}

// Serve the cache if file isn't store in the client browser cache
readfile( $rocket_cache_filepath );
exit;
Expand Down Expand Up @@ -361,7 +362,7 @@ function rocket_define_donotminify_constants( $value ) {
if ( ! defined( 'DONOTMINIFYCSS' ) ) {
define( 'DONOTMINIFYCSS', (bool) $value );
}

if ( ! defined( 'DONOTMINIFYJS' ) ) {
define( 'DONOTMINIFYJS', (bool) $value );
}
Expand Down

0 comments on commit cdf17e8

Please sign in to comment.