<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.
Comments (11)
I hope you enjoy this discussion. In any case, I ask you to join it.