Hey everyone! This is Scott from sertmedia.com and in this video I'm gonna be
answering a question regarding WooCommerce and the Ajax cart fragments.
A lot of people want to know how to disable it and I'm going to explain who
should be disabling it. Who shouldn't and what it does. WooCommerce Ajax Cart
Fragments is a script that's included in WooCommerce by default. It's
automatically loaded on all pages and it's what allows your cart to render and
drop down and list the products dynamically. So if you're on a website
and you have something like this. Very simple. It's a drop down cart and it
lists your products, the subtotal, and everything you need to know. This relies
on WooCommerce Cart Fragments. It stores the data and it loads it via Ajax
from the database and it stores it in a session and it's uniquely assigned to
you. You don't technically need this script to have a store. However if you
don't do it, you're going to run into some issues that I need to stress. If
you're using a page caching plugin for instance, you will need, if you do not
have the script enabled, to disable caching for a user who is, who has an
item in their cart and the reason for that is if you don't they won't get any
update notification on their cart. While they go to the cart page, while they
will go to their cart page, checkout page and they may see an item or no items.
It's because the cache system has no way of identifying whose data is what. So you
have to bypass the cache, if you don't use these cart fragments. If you are using
cart fragments, you can technically cache the pages even if somebody is using, if
somebody has a product in their cart and that's because it's being downloaded by
Ajax and doesn't need to make a PHP request to the server to retrieve that
data. So I see this all the time with WooCommerce websites, where somebody will
they come and they say this script is slowing down my site. Really the script
is actually pretty lightweight and efficient. This site's script only loaded
in 190 milliseconds. Some sites it loads in five or ten seconds and it
crashes and it comes down to your server load, your host, if you're running on a
bad host; Hostgator, GoDaddy, Bluehost. I always pick on those three but they're
so prevalent that it needs to be said. You're going to have performance issues.
Ultimately you're getting performance issues because they're not meant to
serve complex pages. They're just not and they will throttle you and they're
just not fast servers. You had a fast site because you're serving it as HTML
which they're quite efficient at, but when you're serving a store, it's not
that easy. So now that we've actually gone over really whether you should or
shouldn't. It's gonna come down to if you're using a caching plugin, you're
going to need to exclude your pages. If you're simply just wanting to disable it
altogether because the hosts you have right now is slow and you don't want to
deal with it. There are some things. Number one make the exception in your cache
like I mentioned. Alright. Number two. You're gonna go to your WooCommerce
settings and we're actually going to make a change and we want to make this
change because we don't want to cause issues with users who are adding
products. For the "add to cart" behavior disable the Ajax Add to Cart button and I
would just redirect to the cart page after successful addition. If you're
having a site where most people will only buy one product this is just going
to give you a pretty seamless experience, but the best experience in my opinion is
just to leave the Ajax cart fragments script enabled. I've seen themes too that
depend on this script, if you click on your cart and it opens on the sidebar,
it's gonna depend on the script. So keep this all in mind now we've disabled that.
Though we are going to just add a simple plugin. You can do this from a variety of
plugins. There's some on the store, on the with a wordpress.org store. I'll give you
a link to it. I have one that I wrote that's just called quite frankly
disable cart fragments from loading
slowing down your website. What this does is it dequeues the script from loading on
the front end. Because it's not loading anymore, it will
no longer have an impact on the website. There's no more Ajax request to be made.
You can do this with perfmatters too and I believe I remember reading on their
road map they're working on a way to only load it, if somebody added a product
to their cart. That's something to keep in mind. I use perfmatters all the time,
but for the sake of this, I wanted to give you a free option. So you go ahead
and you run it. If we've enabled our plugin. I'll include the link to this
specific plugin as well. I'm gonna purge all the caches and I'm going to run
another GTmetrix test and what we're looking for is to see that this script
right here has disappeared and GTmetrix has been a little backed up today, so I'm
hoping I can squeeze right on by and get this test in but um while this runs just
just keep in mind that the cart fragments it might have an impact in
your fully loaded time, but you should really think of the impact on the user
experience and your menu functionality for illustrating to your customers what
products they have. So we went ahead and we removed it, For those of you who are
curious, this was the before we removed it, it was 282 kilobytes, 32 requests and
now it's 278 kilobytes and 29 requests. Don't worry about the fully loaded time
going up because the pages are not cached and varnished like they were on
the first run, but the request is no longer there. it's completely gone and
your website may be better off for it and maybe it will not be. This is kind
of the low-hanging fruit I would say if you're trying to optimize your
WooCommerce store. Don't start with this. If you're coming down to the wire
with things that you can do and you're considering it, that's when I would look
at it, but this is, this is not something that's really going to do all that much
for you and actually solving major performance issues that you may be
happening on your store. If you have any questions, as always please feel free to
ask in the comments below. I will try to help you out as best I can. Make sure to
like and subscribe and I will see you in next one.