Where to host Javascript for blogger blogs?
Blogger does not provide file hosting, (except for photos and videos, in Picasaweb). This poses problem if you want to add a widget or a feature that uses Javascript. Where do you put the scripts then?
Below are some of the options you have when adding Javascripts to your Blogger or blogspot blog.
1. Put it in a widget
If the script is small and used only for that particular widget then this is the preferred method. Just put the script in an HTML/Javascript gadget/widget together with the rest of the widget codes, like this:
<script type='text/javascript'> put javascript code in here </script>
Most of my hacks use this method. I like this method because it’s easier to install, uninstall and you don’t need to mess with your template code.
2. Put it in the template itself
Use this method if the script is accessed from outside of a widget or from more than one places in your template. Do it like this:
<script type='text/javascript'> //<![CDATA[ put javascript code here //]]> </script>
Then place the whole thing before the </head> tag in your template.
3. Host the javascript file externally (outside of Blogger server)
To be specific use Google Sites. Why Google Sites? Because it’s free first and foremost (that’s why you join Blogger in the first place right?) and it’s a part of Google big family, so you don’t have to sign up or anything.
But Google Sites, like most free host doesn’t accept javascripts. Luckily there is a workaround -change the javascript file into a text file, by changing the file extension from .js to .txt.
Note: The external script must not contain the <script type='text/javascript'></script> tags.
After uploading the file to Google Sites, get the direct link to the file and use it in the code below (notice the .txt file extension).
<script src='filename.txt' type="text/javascript'/>
The direct link to the file will begin with https. To make it work, you need to change https to http when adding to the code, like in this example:
<script src='http://sites.google.com/site/bloggersentral/file-storage/shBrushXml.txt' type='text/javascript'/>
This code must be positioned exactly where you would want the script to be in your template.
Enjoy!
14 comments to "Where to host Javascript for blogger blogs?"
I think that your workaround mentioned in item 3 only works if the referrer is a Google domain. See http://www.google.com/support/forum/p/sites/thread?tid=4460cf8b5c19140f&hl=en
... doug
@ocapta
The .js-to-.txt hack should work equally well in both Blogger custom domain and blogspot domain.
The help forum's thread above only discusses .js and .css files.
Good info, thanks for sharing :)
Thanks, It is a very helpful article, I did it and it seems to work. Peace
Thank you so much! I've been searching around so long on how to get emoticons into my posts and this helps soooo much!
THANK YOU SO MUCH! this was what I was looking for, super helpful!
how to use JavaScript in post ?? i want to use it blogger post not in widget nor in template. please help me !!!
@Techehub
Put the script in a script tag, like so:
<script>
PUT SCRIPT HERE
</script>
and place it in your post's HTML.
Thanks a lot for this solution..worked for me perfectly. Now I can use that gadget easily.
Thanks for sharing. Its good to see fresh content always.
plz tell me how to add code box to blogger my mail id gsruthin@gmail.com
i dont i don kow .what went wrong i need your help
pls
my emaila
thanks for sharing your javascript tutorial
thx
To ensure proper display, HTML/XML/Javascript need to be escaped first using this escape tool. Then paste the escaped code here. For personalized help, you can HIRE ME.