Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Buttigieg GeekPress

View GitHub Profile
View speed-up-404-static-files.php
<?php
/**
* Plugin Name: Speed Up 404 Static File
* Description: Skip WordPress handling 404 on static files to avoid lack of performance.
* Author: GeekPress
* Licence: GPLv2 or later
* */
$path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
$path = trim( $path, '/' );
@GeekPress
GeekPress / ajax-cache.php
Created May 3, 2018
admin-ajax.php Request Cache
View ajax-cache.php
<?php
$cached_ajax_requests = array(
'your-action-here',
);
$cached_ajax_expiration_time = 7 * DAY_IN_SECONDS;
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], $cached_ajax_requests ) ) {
$request_id = get_rocket_request_uniqid_171286();
$data = get_transient( 'rocket_get_ajax_cache_' . $request_id );
@GeekPress
GeekPress / gist:372d5072dddf2763063615a489fa5976
Created Apr 25, 2018
Nginx skip WordPress 404 handling for static files
View gist:372d5072dddf2763063615a489fa5976
if (-f $request_filename) {
break;
}
if (-d $request_filename) {
break;
}
if ($request_uri ~ "(robots\.txt|sitemap\.xml(\.gz)?)") {
break;
@GeekPress
GeekPress / .htaccess
Created Apr 25, 2018
.htaccess skip WordPress 404 error handling for static files
View .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(robots\.txt|sitemap\.xml(\.gz)?)
RewriteCond %{REQUEST_FILENAME} \.(css|js|html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ [NC]
RewriteRule .* - [L]
</IfModule>
@GeekPress
GeekPress / cache-woo-get-refreshed-fragment-request.php
Last active Jul 25, 2019
Cache WooCommerce Get Refreshed Fragment Request
View cache-woo-get-refreshed-fragment-request.php
<?php
if ( isset( $_GET['wc-ajax'] ) && 'get_refreshed_fragments' === $_GET['wc-ajax'] && ( !isset( $_COOKIE['woocommerce_cart_hash'] ) || empty( $_COOKIE['woocommerce_cart_hash'] ) ) && ( !isset( $_COOKIE['woocommerce_items_in_cart'] ) || empty( $_COOKIE['woocommerce_items_in_cart'] ) ) ) {
$data = get_transient( 'rocket_get_refreshed_fragments_cache' );
if ( ! empty( $data ) ) {
$data = json_decode( $data );
wp_send_json( $data );
}
ob_start();
@GeekPress
GeekPress / gist:7803194
Created Dec 5, 2013
Expires Headers via htaccess
View gist:7803194
# Expires headers (for better cache control)
<IfModule mod_expires.c>
ExpiresActive on
# Perhaps better to whitelist expires rules? Perhaps.
ExpiresDefault "access plus 1 month"
# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
ExpiresByType text/cache-manifest "access plus 0 seconds"
@GeekPress
GeekPress / gist:7796748
Created Dec 4, 2013
Compression Gzip via .htaccess
View gist:7796748
<IfModule mod_deflate.c>
# Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
</IfModule>
</IfModule>
# Compress all output labeled with one of the following MIME-types
You can’t perform that action at this time.