A virtual teacher who reveals to you the great secrets of Base64

<script>

The <script> tag executes client-side scripts (typically, JavaScript). It may contain source code inside “itself” or may load it from an external file specified within the src attribute. Like other HTML tags that have the src attribute, the <script> tag supports data URIs.

As is the case with the <link> tag, there is no reason to use data URI to embed scripts, because you can embed scripts as source code. It is easier, faster and smaller. Below I provide three examples that do the same thing, but the data URI is just for fun.

Example #1 (load script from external URL):

<script src="//static.base64.guru/uploads/js/welcome.js"></script>

Example #2 (embed script using data URI):

<script src="data:text/javascript;base64,YWxlcnQoJ1dlbGNvbWUgdG8gYmFzZTY0Lmd1cnUhJyk"></script>

Example #3 (embed script as source code):

<script>alert('Welcome to base64.guru!');</script>

By the way, if you are looking for JavaScript Base64 functions, check the atob and btoa.

Add new comment

If you have any questions, remarks, need help, or just like this page, please feel free to let me know by leaving a comment using the form bellow.
I will be happy to read every comment and, if necessary, I will do my best to respond as quickly as possible. Of course, spammers are welcome only as readers.

Loading...