JavaScript
How script.js is loaded
Order: approved CDN scripts (deferred) → templates/<name>/script.js (deferred) → /assets/storefront/engine.js (deferred) → <script id="love-config-json" type="application/json"> config. script.js runs before the engine, so it can set window.StorefrontTheme; use its callbacks to act after the engine starts.
Libraries on the page: jQuery 3.7.1 ($), SweetAlert2 11 (Swal), Font Awesome 6.4 (CSS), Bootstrap 5.3.2 (CSS only).
What the JavaScript sanitizer changes
script.js is rewritten with these patterns (the matching code stops working). security.js:518
| Code | Pattern |
|---|---|
| document.createElement("script") | /document\s*\.\s*createElement\s*\(\s*['"]script['"]\s*\)/gi |
| .createElement("script") | /\.\s*createElement\s*\(\s*['"]script['"]\s*\)/gi |
| new Function( | /\bnew\s+Function\s*\(/g |
| eval( | /\beval\s*\(/g |
| setTimeout/setInterval with a string | /\b(setTimeout|setInterval)\s*\(\s*(['"])/g |
| import() of a remote URL | /\bimport\s*\(\s*(['"])\s*(https?:)?\/\//gi |
| fetch/XMLHttpRequest/WebSocket/EventSource to an absolute remote URL | /\b(fetch|XMLHttpRequest|WebSocket|EventSource)\s*\(\s*(['"])\s*(https?:)?\/\//gi |
| document.write( | /\bdocument\s*\.\s*write\s*\(/g |
The CSP also blocks inline scripts and connections to other sites (see CSP).
window.StorefrontTheme (input)
Optional object defined by script.js before engine.js runs. public/assets/storefront/engine.js:7
| Property | Description | Source |
|---|---|---|
labels | Object of words the engine uses (see labels). Overridden by template.json "labels". | public/assets/storefront/engine.js:85 |
icons | Font Awesome classes for engine-rendered icons: cart, wishlist, emptyCart, browse, categoryDefault, brand. | public/assets/storefront/engine.js:90 |
categoryIcons | Extra keyword → icon class pairs for category tiles (matched against category names). | public/assets/storefront/engine.js:106 |
buttonColor | Confirm-button colour for SweetAlert2 dialogs (defaults to branding.primaryColor). | public/assets/storefront/engine.js:108 |
onSection | function(route, params, App) called after every route change. | public/assets/storefront/engine.js:745 |
instantFilters | Set to false so filters apply only when #applyFiltersBtn is pressed. | public/assets/storefront/engine.js:1101 |
categoryImages | Set to false to always use icons instead of category images. | public/assets/storefront/engine.js:1236 |
onInit | function(App) called before the engine boots. | public/assets/storefront/engine.js:3175 |
onReady | function(App) called once the store context, session and cart are loaded. | public/assets/storefront/engine.js:3202 |
window.StorefrontTheme = {
labels: { cart: 'Basket' },
onReady: function (App) {
// the engine has started; App is window.Storefront
},
onSection: function (route, params, App) {
// after every page change
}
};
window.Storefront (output)
The running engine. Passed as "App" to onInit/onReady/onSection. Also available as window.LoveApp. public/assets/storefront/engine.js:170
addToCart api cancelOrder cart cartApi cartMismatch cartSignature cartStoreAvailable cartStoreId checkout clearFilters clearFormNotification closeModal coupon currentImageIndex currentProduct currentSection currentVariant errorMessage facets facetsLoader filterByBrand filterByCategory formatMoney goToStep hero heroSliderNext heroSliderPrev imageTag loadProducts loadProfile logout navigateTo nextCheckoutStep onSection openModal openOrderDetail openProductDetail paymentGateways performSearch placeOrder prevCheckoutStep proceedToCheckout productCardHtml quickAddToCart recentlyViewed removeFromWishlist safeImageUrl sections showFormNotification showLoginModal showRegisterModal showSection showToast store storeUI switchProfileTab toggleWishlist user util variantLabel wishlist wishlistRemote
data-action values
Elements with data-action="…" run engine actions on click (49): cancel-order cart-clear cart-remove checkout-goto checkout-next checkout-prev checkout-retry choose-store clear-filters close-filters close-modal close-nav close-search close-store-modal coupon-remove delete-address dismiss-checkout-badge edit-address filter-brand filter-category hero-next hero-prev logout open-filters open-product order-done order-view pd-add pd-thumb pd-variant pd-wishlist place-order proceed-checkout quick-add refresh-captcha reload-products remove-wishlist retry-stores search search-all select-store show-login show-register toggle-billing toggle-nav toggle-search toggle-wishlist view-order wishlist-to-cart
Sections with their own handlers: products, featured, product-detail, wishlist, cart, checkout, profile, terms, refund-policy, privacy-policy. The engine uses delegated jQuery handlers, so elements added later still work.