Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Disable Woocommerce cart fragments for homepage via .htaccess
# By creating empty response
# Please replace yoursite.com
# Disable only on homepage
RewriteEngine On
RewriteCond %{HTTP_REFERER} ^https://yoursite.com/$ [NC]
RewriteCond %{QUERY_STRING} ^wc-ajax=get_refreshed_fragments$
RewriteRule ^(.*)$ $1 [R=204,L]
# Disable everywhere
RewriteEngine On
RewriteCond %{QUERY_STRING} ^wc-ajax=get_refreshed_fragments$
RewriteRule ^(.*)$ $1 [R=204,L]
@guikare

This comment has been minimized.

Copy link

guikare commented Nov 22, 2018

doesnt work!

@cultd3ad

This comment has been minimized.

Copy link

cultd3ad commented Dec 3, 2018

for me works on Apache 2.4 with nginx Proxy

@virgilshelton

This comment has been minimized.

Copy link

virgilshelton commented Dec 5, 2018

Works, thanks on Apache 2!

@lukapaunovic

This comment has been minimized.

Copy link
Owner Author

lukapaunovic commented Jan 2, 2019

@guikare

doesnt work!

It doesn't work with some configurations, so here's an alternative that does.
It requires creating a blank 404.php file from which we'll get a blank response

# BEGIN Disable cart fragments
RewriteEngine On
# Uncomment rule bellow and update with your site url if you want to disable only for homepage
#RewriteCond %{HTTP_REFERER} ^https://yoursite.com/$ [NC]
RewriteCond %{QUERY_STRING} ^wc-ajax=get_refreshed_fragments$
RewriteRule ^(.*)$ /404.php [NC,L]
# END Disable cart fragments
@jayeq

This comment has been minimized.

Copy link

jayeq commented Jan 28, 2019

Didn't work for me (tried disabling everywhere) but the alternative seems better for me. It does cause a 500 error based on the waterfall but at least it's quick vs. the 1s+ the call was taking before. Thanks!

As for that internal error, it makes me believe something's not right since it should be finding the 404.php file I created, no??? Any ideas on how to fix that? Sometimes, it's taking >500ms to return the 500 error...

@lukapaunovic

This comment has been minimized.

Copy link
Owner Author

lukapaunovic commented Feb 2, 2019

@jayeq, if you are using the method which uses 404.php file then you need to create that file, of course.

The content of the 404.php file should be:

<?php
http_response_code(204);
die();

Then in waterfall u should see 204 response instead of 500 error.

@Solgaz

This comment has been minimized.

Copy link

Solgaz commented Dec 6, 2019

I used your settings all the time and it was great!
It doesn't work anymore. Could give new instructions ..?
My site
WooCommerce 3.8.1
WordPress 5.3
PHP 7.4
MySQL 5.7.16-10-log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.