About the Javascript to Base64 Converter
Source code is full of characters that other formats treat as special: quotes, backslashes, angle brackets, template literal backticks and dollar braces. Push a script through a YAML value, a shell argument or a JSON field and something usually breaks. Base64 flattens all of it into the plain alphabet, and the code comes back byte identical.
Three shapes are available. Raw Base64 is the bare payload for a config field or a database column. The data URI carries the data:text/javascript;charset=utf-8;base64, prefix, which is what a dynamic import or a worker constructor expects. The script tag wraps that URI in a complete element, which is convenient for a self contained demo page or an email preview where there is nowhere to host a file.
The trim option removes trailing whitespace from every line and collapses runs of blank lines into one. It leaves the code fully readable, unlike a minifier, and it usually shaves a few percent off a hand written file where editors have left ragged line ends behind.
Modern browsers block data URI scripts under most Content Security Policies, so treat the script tag as a tool for local pages and previews rather than production. Encode a whole page instead with HTML to Base64, shrink first with JavaScript Minifier, or decode with Base64 to JavaScript.
How to use
- Paste your script into the left pane.
- Choose Output as: raw Base64, a data URI, or a full script tag.
- Tick Trim line ends to clean up ragged whitespace before encoding.
- Copy the result into your config, template or page.
Common questions
- Will a data URI script run in a normal page?
- Often not. Content Security Policies commonly block script data URIs, so it is best kept for local files and previews.
- Are template literals and backticks safe?
- Yes. Every byte is encoded, so backticks, dollar braces and regular expressions survive unchanged.
- Does the trim option change behaviour?
- No. It only touches trailing whitespace and blank lines, neither of which affects how JavaScript runs.
- How much larger is the encoded form?
- About a third larger, plus the prefix. Minifying before encoding is the effective way to keep it small.