How-To Host JavaScript or JS Files on Blogger Itself (Updated)

Learn how to Host JavaScript inside Blogger Itself

generally-speaking, most JavaScript tutorials teach us to host our .JS JavaScript files offsite, by linking to them like this:

<script src='http://your-host-url/file.js' type='text/javascript'/>

➢ Erik Arvidsson's Depressible DHTML Buttons tutorial at Dynamic Drive, for instance, require us to host an external coolbuttons.js file.

For bloggers, there are four problems with this approach.

➢ One. You have to host your files with a remote host, with support for hot-linking (i.e. linking directly to the hosted JS file). As far as I know, only Dropbox [2], Google Code Project Hosting [2], Google Sites and Your JavaScript [2] currently supports hot-linking, meaning you will have to create an additional 'site', or register an additional account, with the sole purpose of hosting your JS files.

➢ Two. Remote servers may go down from time-to-time, in the process crumbling your site.

➢ Three. Hosting files on remote servers may also severely affect the loading time of your site.

➢ Four. Hosting external .JS JavaScript files in your template will leave them functional throughout your site; while embedding a Java Script inside a particular post will only allow it to function when that particular post is viewed. For example, when accessing my post on Streampad you will be met with a streaming media player, only available on that particular post.

So, how do we resolve these problems?


To invisibly, yet actively, embed the content of a .JS JavaScript file inside a post, you will need to contain it within a CDATA Section. This will "tell the parser that there is no markup in the characters contained by the CDATA section" [3].

<script type='text/javascript'>

Well, I hope that helps.


1. How To Host Javascript Or .js files on Blogger Itself (Anshul Dudeja; September 2009) ✔
2. Best places on web to host your JavaScript files (Bloggerz Bible; 22 February 2011) ✔
3. CDATA Sections [XML Standards] (Microsoft Developer Network; 29 May 2012) ✔


28.05.2012 / 04.01.2014
Older Posts