jQuery in 2026: The Case for Keeping It on Server-Rendered Shopify Pages
Last month we took on a redesign for a standalone site, a Shopify theme, with the core being the product detail page: variant switching, add-to-cart, cart drawer, stock hints, plus a few marketing modules.
On the day of the technical review, I wrote one line in the document: The interaction layer uses jQuery, no React is introduced.
After sending the document to the group, a colleague directly replied with a meme 😑
Another person privately messaged me asking if I'd been too tired lately. The most extreme was a guy born after 2000 who seriously asked: Is jQuery the thing that starts with $? I've only seen it in interview questions.
I didn't rush to explain. I first asked them to calculate the numbers for the React approach.
First, look at what the page looks like
The Shopify theme's page is server-side rendered by Liquid templates. Product title, price, images, variant options, SEO structured data, all are ready-made HTML, and the browser can display them immediately.
What the frontend needs to do is:
These are all enhancements to existing HTML, not rendering a page from scratch.
My colleague's React approach: use Vite to bundle a few React island components and mount them into the theme. To avoid flash, the variant area and cart would need to be re-rendered on the client, with data passed into the page as JSON from Liquid.
The approach itself is fine, but after calculating, three problems emerged:
Size
react + react-dom compressed is over 40 KB. Adding business code and state management, the product page gains about 120 KB of JS. Our users largely come from Southeast Asia and the Middle East, with a high proportion of low-to-mid-end Android phones. The product page's LCP and INP directly affect ad quality score and conversion rate, so this 120 KB isn't free.
Double rendering
The server already rendered the variant area with Liquid, and the client React renders it again. The two templates must stay consistent, so price formatting, multi-currency, and multi-language logic must be written twice. When an operator changes a block configuration in the theme editor, the React side might not sync.
Maintainers
After this site goes live, daily maintenance is done by an operations person plus an outsourced developer, changing copy, adjusting blocks, occasionally adding a small feature. They directly edit files in the Shopify backend's code editor, with no build process. Adding React means every change requires our team to build and deploy.
After calculating these three costs, the group chat went quiet 🤔.
Then why not just write native JS
This was the most asked question in the review, and the most valid one.
Honestly, native DOM API is now fully sufficient. querySelector, fetch, classList, event delegation, and Shopify's official Dawn theme is written with native JS plus Web Components, and it's beautifully done.
My reason for choosing jQuery is very practical: the theme's third-party ecosystem can't live without it.
We installed 7 Shopify Apps for reviews, subscriptions, bundle sales, size charts, and when the page opens, 4 of them automatically inject jQuery. There's already a copy of jQuery sitting on the page, so writing my own native event and animation utility functions would be reinventing the wheel. Also, the outsourcer and operations staff can both read jQuery, and handover cost is essentially zero.
What the actual code looks like
Using jQuery doesn't mean writing it like it's 2012. Here's the core logic for variant switching and add-to-cart, with key points in comments:
// assets/product-form.js
(function ($) {
'use strict';
// All events are namespaced for easy cleanup when a Section is unloaded
const NS = '.productForm';
function initProductForm(root) {
const $root = $(root);
// Variant data is output by Liquid: {{ product | json }}, read once at init
const product = JSON.parse($root.find('[data-product-json]').text());
const moneyFormat = $root.data('money-format');
let pendingAdd = null; // current in-flight add-to-cart request
function findVariant(options) {
return product.variants.find((v) =>
v.options.every((opt, i) => opt === options[i])
);
}
function render(variant) {
const $btn = $root.find('[data-add-to-cart]');
if (!variant) {
$btn.prop('disabled', true).text($btn.data('text-unavailable'));
return;
}
// Use .text() instead of .html(); variant titles come from admin input, cannot be trusted
// formatMoney is the theme's public utility, handles multi-currency per shop's money_format
$root.find('[data-price]').text(formatMoney(variant.price, moneyFormat));
$root.find('[data-variant-id]').val(variant.id);
$btn
.prop('disabled', !variant.available)
.text(variant.available ? $btn.data('text-add') : $btn.data('text-soldout'));
if (variant.featured_media) {
$(document).trigger('product:media-change', [variant.featured_media.id]);
}
// Only update the URL without refreshing, so users can share a specific variant
const url = new URL(window.location.href);
url.searchParams.set('variant', variant.id);
window.history.replaceState({}, '', url.toString());
}
// Event delegation: marketing apps may re-render buttons, direct binding would lose events
$root.on('change' + NS, '[data-option-input]', function () {
const options = $root
.find('[data-option-group]')
.map((_, group) => $(group).find('input:checked').val())
.get();
render(findVariant(options));
});
$root.on('submit' + NS, 'form[action$="/cart/add"]', function (e) {
e.preventDefault();
const $btn = $root.find('[data-add-to-cart]');
// On rapid clicks or weak network, abort the previous request and only accept the last
if (pendingAdd) pendingAdd.abort();
$btn.prop('disabled', true).addClass('is-loading');
pendingAdd = $.ajax({
url: '/cart/add.js',
method: 'POST',
dataType: 'json',
data: $(this).serialize(),
timeout: 10000,
})
.done((item) => {
$(document).trigger('cart:item-added', [item]);
})
.fail((xhr, status) => {
if (status === 'abort') return; // aborted by newer request, don't show error
// Shopify returns 422 for insufficient stock, description is the message for users
const msg = xhr.responseJSON?.description || $root.data('text-error');
$root.find('[data-form-error]').text(msg).prop('hidden', false);
})
.always((_, status) => {
if (status === 'abort') return;
pendingAdd = null;
$btn.prop('disabled', false).removeClass('is-loading');
});
});
// Return a cleanup function, used when the theme editor unloads a Section
return function destroy() {
if (pendingAdd) pendingAdd.abort();
$root.off(NS);
};
}
// Each instance records its own cleanup function
const instances = new WeakMap();
function mount(container) {
$(container).find('[data-product-form]').each(function () {
instances.set(this, initProductForm(this));
});
}
function unmount(container) {
$(container).find('[data-product-form]').each(function () {
instances.get(this)?.();
instances.delete(this);
});
}
$(function () { mount(document); });
// Every time the theme editor changes a block config, Section is reloaded
// Without cleanup, multiple submit listeners stack on the same button, one click adds multiple items
$(document)
.on('shopify:section:load', (e) => mount(e.target))
.on('shopify:section:unload', (e) => unmount(e.target));
})(window.jQuery);
The entire product page's interaction code compresses to about 6 KB. Combined with the jQuery already on the page, the added cost is almost negligible. After launch, the product page's mobile LCP improved by 0.6 seconds compared to the old version, and INP stayed stable under 150ms.
Pitfalls to avoid when using jQuery
jQuery has been criticized for many years, and not all of it is undeserved. If you really use it, handle these issues upfront.
Multiple version conflicts
As mentioned, 4 Apps inject jQuery, and the versions differ, some 1.x and some 3.x. The one loaded later overwrites window.$, so your plugin might attach to one version and by the time it's called, it's already been swapped to another.
Our approach: the theme loads its own fixed version and immediately uses noConflict to get a private reference. Business code only uses this reference:
<!-- layout/theme.liquid: placed before all App scripts -->
<script src="{{ 'jquery-3.7.1.min.js' | asset_url }}"></script>
<script>
// Get the theme's private jQuery, unaffected by how Apps later overwrite window.$
window.ThemeJQ = jQuery.noConflict(true);
</script>
Then replace the final line of the business files' window.jQuery with window.ThemeJQ.
.html() is a hotbed for XSS
Many XSS vulnerabilities from the jQuery era come from $(el).html(userInput) and $(userInput) patterns. Product titles, review content, discount codes, and such fields could be written with weird stuff by backend accounts or third-party Apps.
Team rule is simple: use .text() for dynamic content always, and if structure truly needs to be inserted, clone <template> nodes and fill with textContent. In Code Review, search for .html( and every occurrence must explain the data source.
Once state gets complex, switch
jQuery suits interactions with little state, scattered, and short-lived. On our product page, the state is the currently selected variant and cart quantity, two modules communicate via custom events, more than enough.
But if the requirements become: multi-step custom products, real-time previews, dozens of linked fields, undo/redo. Using jQuery to manually sync the DOM then quickly becomes unmanageable. That's when you should bring in React or Vue, mount only that one block, and don't hesitate.
One month after launch, the colleague who originally sent the meme came to ask if the marketing campaign page could be written the same way. I said yes, but the backend order management system should still seriously use React.
jQuery is certainly not a technology worth praising; its problems are known to everyone. But whether a technology should be used depends on page shape, team, maintainers, and performance budget, not the year it was released.
Server-rendered content sites, e-commerce themes, marketing pages: they need enhancement. Backend systems, complex editors, heavy-interaction apps: they need rendering. Distinguish these two, and most technology selection debates become unnecessary.
Do you still have jQuery in your current projects? 😃
If you like my articles, follow my WeChat public account: 【前端技术官】.
Main topics: Frontend Architecture · AI Programming · Career Insights · Developer Growth
Scan the QR code to follow 👆
Updates irregularly, no spam, only practical dry goods.
Top 5 of 11 from juejin.cn, machine-translated. The original thread is authoritative.
After reading it, the core point is still that jQuery is being kept because there's already a dependency on it, right? I feel this is more like technical debt. As for outsourcing and operations being more familiar with it, now that AI writes code, I don't think that reason holds up either. Really, it comes down to what the project itself needs—I don't understand Shopify, so I won't comment on that.
Shopify's SSR rendering is HTML-like and not complex, so using a modern framework isn't appropriate.
I didn't say to use Vue/React or similar frameworks, but since you say it's not appropriate, then what about the passage in the article: 'But if the requirements become: multi-step product customization, real-time preview, dozens of linked fields, undo/redo—then using jQuery to manually sync the DOM will quickly spiral out of control. In that scenario, switch to React or Vue, and mount it only in that one section, without hesitation.' Was that said outside the context of Shopify? I thought it implied it could be used in Shopify.
The frontend is dead, and you're still asking if jQuery is dead.
[dejected][dejected]
I haven't used jQuery in a long time. Recently I used AI to make a mini-program: for curing couples' fights and family discord [melon-eating crowd]
Welcome big shots to give valuable suggestions.
How was this image made?
Gemini.
[melon-eating crowd][melon-eating crowd]