Inline JavaScript Deferrer (defer & async)
Turn inline scripts into deferred or async script tags so they stop blocking page render, and turn them back when you need to.
What it is for?What it is for?
A script tag without src runs the moment the browser reaches it, and the page waits until it finishes. Analytics snippets, chat widgets and theme scripts pasted into the head all hold up the first paint this way. This tool turns such inline code into a script tag that can be deferred, and turns it back when you need to edit it.
Why defer inline scripts?
Deferred and async scripts do not block rendering, so the page appears sooner and the PageSpeed score goes up. Async is fastest, but many older templates expect scripts to run in order, so defer is the safer choice. An inline script cannot be deferred on its own. This tool wraps it in a data URL so the defer attribute applies to it.
Example
console.log('test');
will be converted to
<script defer src="data:text/javascript;base64,Y29uc29sZS5sb2coJ3Rlc3QnKTs="></script>
You can replace defer with async if the script does not depend on others.
How to use it
- Paste only the JavaScript, without the opening and closing script tags. Whatever you paste is encoded as it is, tags included.
- Tick Minify first to compress the code before it is encoded. The base64 string is about a third larger than the code it holds, so minifying helps.
- Replace the original inline script with the generated tag. To edit the code later, paste the tag here and press Decode.
Before you switch
- A deferred script runs after the HTML is parsed. Code that uses document.write, or that another inline script needs right away, will break.
- If your site sends a Content-Security-Policy header, script-src must allow data: or the browser will refuse to run the script.
Where your code goes
Encoding and decoding run on our server. The code is sent with the request and the result is returned; the tool does not save it.