Friday, June 22, 2018

Sitecore Experience Commerce - Remove Commerce Experience Accelerator JavaScript

Out of the box, if you have a site running Sitecore Experience Commerce (even with a completely custom theme) some JavaScript will get added to the page. This happens if you are using AssetLinksGenerator.GenerateLinks to give you the required CSS and JS to output on the page.

Theses scripts (as on update 1) appear as:
<script src="/Scripts/Commerce/Services/cxa.services.dom.observer.js"></script>
<script src="/Scripts/Commerce/Services/cxa.services.messaging.js"></script>
<script src="/Scripts/Commerce/Services/cxa.services.ajax.js"></script>
<script src="/Scripts/Commerce/Services/cxa.common.productselection.js"></script>
<script src="/Scripts/Commerce/Services/cxa.common.productprice.js"></script>
<script src="/Scripts/Commerce/Services/cxa.services.cart.context.js"></script>
<script src="/Scripts/Commerce/Core/cxa.core.application.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.productlistsorting.js"></script>
<script src="/Scripts/Commerce/Core/cxa.core.component.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.orders.model.js"></script>
<script src="/Scripts/Commerce/Feature/Cart/cxa.feature.cart.models.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.productlistitemsperpage.js"></script>
<script src="/Scripts/Commerce/Core/cxa.core.startup.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.recent-orders.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.order-history.js"></script>
<script src="/Scripts/Commerce/Feature/Cart/cxa.feature.cart.addtocart.js"></script>
<script src="/Scripts/Commerce/Feature/Checkout/cxa.feature.checkout.address.model.js"></script>
<script src="/Scripts/Commerce/Core/cxa.core.form.js"></script>
<script src="/Scripts/Commerce/Feature/Cart/cxa.feature.cart.addtocart.productselection.handler.js"></script>
<script src="/Scripts/Commerce/Feature/Checkout/cxa.feature.checkout.delivery.model.js"></script>
<script src="/Scripts/Commerce/Feature/Cart/cxa.feature.cart.lines.model.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.catalog.productprice.model.js"></script>
<script src="/Scripts/Commerce/Feature/Checkout/cxa.feature.checkout.billing.model.js"></script>
<script src="/Scripts/Commerce/Feature/Cart/cxa.feature.cart.lines.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.catalog.productprice.js"></script>
<script src="/Scripts/Commerce/Feature/Checkout/cxa.feature.checkout.review.model.js"></script>
<script src="/Scripts/Commerce/Feature/Cart/cxa.feature.cart.total.js"></script>
<script src="/Scripts/Commerce/Feature/Checkout/cxa.feature.checkout.delivery.js"></script>
<script src="/Scripts/Commerce/Feature/Cart/cxa.feature.cart.total.model.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.catalog.productinventory.model.js"></script>
<script src="/Scripts/Commerce/Feature/Checkout/cxa.feature.checkout.billing.js"></script>
<script src="/Scripts/Commerce/Feature/Cart/cxa.feature.cart.promotion.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.catalog.productinventory.js"></script>
<script src="/Scripts/Commerce/Feature/Checkout/cxa.feature.checkout.review.js"></script>
<script src="/Scripts/Commerce/Feature/Cart/cxa.feature.cart.promotion.model.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.catalog.productvariant.model.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.catalog.productvariant.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.productfacets.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.productlist.js"></script>
<script src="/Scripts/Commerce/Feature/Minicart/cxa.feature.minicart.model.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.productlist.model.js"></script>
<script src="/Scripts/Commerce/Feature/Minicart/cxa.feature.minicart.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.promotedproducts.js"></script>
<script src="/Scripts/Commerce/Feature/Catalog/cxa.feature.promotedproducts.model.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.registration.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.login.js"></script>
<script src="/Scripts/Commerce/Feature/LanguageSelection/cxa.feature.language.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.forgotpassword.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.changepassword.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.profileeditor.js"></script>
<script src="/Scripts/Commerce/Feature/MessageSummary/cxa.feature.messageSummary.model.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.address.list.js"></script>
<script src="/Scripts/Commerce/Feature/MessageSummary/cxa.feature.messageSummary.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.address.list.model.js"></script>
<script src="/Scripts/Commerce/Feature/Navigation/cxa.feature.navigationbar.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.address.editor.js"></script>
<script src="/Scripts/Commerce/Feature/Account/cxa.feature.address.editor.model.js"></script>
If you don't require any of this JavaScript, they can be stopped from being output by patching out the logic with the following configuration patch file.
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
    <sitecore>
        <pipelines>
            <assetService>
                <processor type="Sitecore.Commerce.XA.Foundation.Common.Pipelines.AssetService.AddJavaScript, Sitecore.Commerce.XA.Foundation.Common">
                    <patch:delete />
                </processor>
            </assetService>
        </pipelines>
    </sitecore>
</configuration>
Appears to save quite a few requests, which should speed up page load times as well.

No comments:

Post a Comment