Dev.to WebDev 🛠 Dev 👁 1 📖 3 min read

Self-Hosting Free Calculator Widgets: MIT-Licensed, One File, Zero Runtime Requests

Every time I publish an embeddable widget, the same two questions arrive: what does your script actually do on my page, and what happens to my page if your site goes away. For most third-party embeds the honest answer is

Every time I publish an embeddable widget, the same two questions arrive: what does your script actually do on my page, and what happens to my page if your site goes away. For most third-party embeds the honest answer is "trust the vendor". I wanted a better answer for the nine calculator widgets my site ships, so I made them boring on purpose: MIT-licensed, plain JavaScript, one file per widget, zero network requests at runtime. This post is the tour: what is in the files, how to audit them yourself, and three ways to host them.

What you are embedding

Nine widgets: mortgage, loan, compound interest, BMI, calorie and TDEE, pregnancy due date, percentage, countdown timer, and word counter. Each one is a single static JavaScript file between 5KB and 11KB. No framework, no build step, no imports. The embed catalog lists all nine with live previews, and the snippet is two lines:

<div id="pwt-mortgage-widget"></div>
<script src="https://practicalwebtools.com/embed/mortgage-widget.js" defer></script>

The widget renders into the container and all the math runs in the visitor's browser. Once the browser has downloaded the file, the script never contacts my server again. There is nothing to contact: no API behind it.

The audit you should run on any embed script

Do not take my word for it. Before loading someone else's JavaScript, count its network APIs:

curl -s https://practicalwebtools.com/embed/mortgage-widget.js \
  | grep -cE "fetch\(|XMLHttpRequest|WebSocket|sendBeacon|import"

For these widgets the answer is 0. The same grep for document.cookie, localStorage, and friends is also 0: the scripts do not read or write any storage. Then open the file in an editor, because 8.5KB is a short read. You will find input fields, a standard monthly-payment formula, and a small render helper. The only URL the code ever builds is the href of that footer link. The most modern API the code touches is Object.assign, so it runs in any browser that still gets updates, with no transpiling.

Three ways to host them

1. Load them from my site. The snippet above. The file is static; the browser fetches it once and everything after that is local.

2. Vendor the file yourself. Save the script, drop it anywhere on your origin, and point the src at your own path:

<div id="pwt-mortgage-widget"></div>
<script src="/assets/js/mortgage-widget.js" defer></script>

This is the option I would pick for an intranet, an air-gapped documentation site, or any project where a content-security-policy review asks why a page loads scripts from a random tool site. It also answers the "what if you disappear" question permanently: a vendored copy keeps working no matter what happens upstream. The files are mirrored in the plugin repository on GitHub under assets/embed/, and jsDelivr serves them too if you want a CDN that is not mine:

<script src="https://cdn.jsdelivr.net/gh/CobraPi/practical-web-tools-calculators@8a9e7be/assets/embed/mortgage-widget.js" defer></script>

(Using jsDelivr means trusting jsDelivr instead of me. That is a reasonable trade, just be explicit with yourself about it.)

3. The WordPress plugin. If you would rather not touch HTML at all, the same scripts are bundled in a small plugin with a shortcode: [pwt_calculator widget="mortgage"]. The plugin ships the nine scripts inside its own directory and enqueues them from your domain, so there are no CDN calls even in hosted mode.

The license, stated plainly

The widget scripts are MIT licensed. That means you can copy them, modify them, ship them in commercial work, translate them, or strip parts you do not want, in any project, without asking. The one obligation is the standard MIT one: keep the copyright and permission notice with substantial copies of the code. A visible link back to my site is not required by the license.

The one ask

Each widget renders a small footer that says "Powered by" and links to the calculator's page on my site, for example the mortgage calculator. It is a plain anchor with no tracking parameters. Keeping it is optional and it is the only payment the widgets ever request. Removing it is allowed; that is what makes the permission meaningful.

If you want to poke at one before deciding, the embed page is the starting point: every widget there has a copy button and a live preview, and the file behind each preview is the same file this article describes.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.