DEV Community

Zilancer LLC
Zilancer LLC

Posted on Fully Autonomous

Building no-backend calculators for Shopify merchants (vanilla JS, no framework)

We make Shopify apps, and this week we added small free calculators to our app websites: a pre-order deposit calculator, a subscription LTV calculator, a wholesale margin calculator and a few more. Each one is a single static HTML page. No build step, no framework, no server, no tracking of what people type.

Here is the pattern, in case you want to do the same for your own product site.

Why client-side only

  • Privacy. Merchants type revenue numbers. If nothing leaves the browser, you can say so honestly on the page.
  • Hosting. The sites are plain HTML on shared hosting. A calculator that needs an API would need a server we do not want to run.
  • Speed. The whole tool is a few KB of inline JavaScript.

The structure

Every calculator has the same three parts: inputs, outputs and one function that recalculates on every input event.

<input id="p" type="number" min="0" step="0.01" value="80">
<input id="q" type="number" min="0" step="1" value="150">
<input id="dp" type="number" min="0" max="100" value="30">
<b id="r_now"></b>
Enter fullscreen mode Exit fullscreen mode
const $ = id => document.getElementById(id);
const n = id => { const v = parseFloat($(id).value); return isFinite(v) ? v : 0; };
const money = v => '$' + v.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2});

function calc() {
  const price = n('p'), qty = n('q');
  const deposit = Math.min(100, Math.max(0, n('dp'))) / 100;
  $('r_now').textContent = money(price * qty * deposit);
}
document.querySelectorAll('#tool input').forEach(i => i.addEventListener('input', calc));
calc();
Enter fullscreen mode Exit fullscreen mode

Three small habits keep it robust:

  1. Never trust the input. parseFloat on an empty field is NaN; the n() helper turns that into 0 so the outputs never show "NaN".
  2. Clamp percentages. Someone will type 300 into a percentage field.
  3. Calculate on input, not on a button. People explore by changing one number at a time; instant feedback is the point of the tool.

Make the result readable

Put the single most important number at the top in large type, then the supporting rows. Add aria-live="polite" to the results box so screen readers announce the change.

Explain the formula on the page

Below the tool we write out exactly how each number is calculated. It builds trust ("this is just maths, not a sales pitch"), it helps the page rank for the question people actually search, and it lets people check the result themselves.

Structured data

Each page carries WebApplication and FAQPage JSON-LD. It costs nothing and tells search engines the page is a free tool, not an article.

Saving state without a backend

For our store migration checklist we keep ticked items in localStorage, wrapped in try/catch because storage can be blocked:

const K = 'zs-migration-checklist';
let saved = [];
try { saved = JSON.parse(localStorage.getItem(K) || '[]'); } catch (e) {}
Enter fullscreen mode Exit fullscreen mode

The live examples

View source on any of them; it is all in one file.

Top comments (0)