Google Operating System Unofficial news and tips about Google

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, 7 June 2011

Better Embedding Code for Google +1 Buttons

Posted on 08:15 by Unknown
Google wants to see a +1 button on each Web page, but many people hate embedding widgets and buttons because they clutter pages and add hundreds of milliseconds to the page loading time.

Google is obsessed with speed and performance, but it didn't do a good job at optimizing the code for embedding +1 buttons. As Aaron Peters explains, Google's code blocks page loading if you place it inside the <head> tag, so it's better to place it before you close the <body> tag. An even better idea is to load the Google +1 script in a non-blocking way, just like Google did with Google Analytics, AdSense and Google Related Links.

Aaron also noticed that the JavaScript code is not minified, browsers can only cache the JavaScript file for 6 minutes and there's a mistake in the code from this page: "http" should be replaced with "https" to avoid an unnecessary redirect.

Here's a better embedding code suggested by Aaron:

<!-- Place this tag just before your close body tag -->
<script>
(function(d, t) {
var g = d.createElement(t),
s = d.getElementsByTagName(t)[0];
g.async = true;
g.src = 'https://apis.google.com/js/plusone.js';
s.parentNode.insertBefore(g, s);
})(document, 'script');
</script>

<!-- Place this tag where you want the +1 button to render -->
<g:plusone></g:plusone>

Apparently, the code doesn't work in Blogger by default. There's a workaround, but you shouldn't use it if you aren't familiar with HTML and editing Blogger's template. Basically you can replace <b:include data='blog' name='all-head-content'/> with the code generated by Blogger ("view source" is your friend), then delete: <meta content='blogger' name='generator'/>.

As Google explains, "most browsers will load the code in parallel with other scripts on the page, thus reducing the web page load time".
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in Social | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Google Clusters Results from Forums
    Google already knows if a page is part of a discussion group and it also extracts useful information like the number of posts or the date o...
  • Google April Fools' Day 2009
    Like last year , many Google services and local sites created their own hoaxes for the April Fools' Day. The most significant announceme...
  • Google Toolbar and 404 Error Pages
    I find it very strange that people have abnormal reactions when Google does something. People have an incorrect perception of the "don...
  • Google Chrome OS Event
    Google will announce more information about Chrome OS at a press event that starts at 10:00am PST. Google will offer "an update on Goog...
  • Disable Google SearchWiki
    Google Search's preferences page includes the option to disable SearchWiki . Just click on the checkbox next to SearchWiki and you'...
  • Interesting Ways to Use Google Chart API
    College @ Home lists 50 ways to use Google Chart API , a simple API for dynamically generating charts. Plot functions, visualize the evolut...
  • Gmail's Shortcut for Inserting Hyperlinks
    Less than 2% of the Gmail users have enabled keyboard shortcuts and actually use them, but that doesn't mean Google shouldn't impro...
  • YouTube Annotations
    YouTube added a new feature for video creators: annotations . "Video Annotations are a new way for you to add interactive commentary to...
  • The Invisible Browser
    Google Chrome has been released and you can now finally try it. Developed in the past two years, the browser is barely noticeable after you...
  • Google Translation Bar
    One of my favorite bookmarklets translates the current web page into English using Google Translate: you can find it here . Unfortunately, G...

Categories

  • Acquisitions (4)
  • Ads (20)
  • AJAX Search (1)
  • Android (20)
  • Annoyances (7)
  • API (11)
  • April Fools Day (6)
  • Blog Search (3)
  • Blogger (26)
  • Book Search (10)
  • Easter Egg (9)
  • FeedBurner (6)
  • Firefox extensions (11)
  • Froogle (5)
  • Gmail (156)
  • Google Analytics (10)
  • Google Apps (11)
  • Google Bookmarks (7)
  • Google Buzz (1)
  • Google Calendar (33)
  • Google Chrome (106)
  • Google Chrome OS (13)
  • Google Co-op (2)
  • Google Contacts (16)
  • Google Desktop (5)
  • Google Dictionary (5)
  • Google Docs (120)
  • Google Drive (9)
  • Google Earth (10)
  • Google Finance (3)
  • Google Gears (17)
  • Google Goggles (4)
  • Google Groups (6)
  • Google Health (4)
  • Google Instant (5)
  • Google Latitude (5)
  • Google Local (6)
  • Google Maps (67)
  • Google Music (10)
  • Google News (23)
  • Google Notebook (6)
  • Google Pack (5)
  • Google Phone (5)
  • Google Photos (1)
  • Google Play (4)
  • Google Plus (45)
  • Google Profiles (11)
  • Google Promos (2)
  • Google Reader (34)
  • Google Scholar (2)
  • Google Sites (7)
  • Google Suggest (20)
  • Google Talk (17)
  • Google Toolbar (21)
  • Google Translate (39)
  • Google Trends (8)
  • Google Update (8)
  • Google Video (20)
  • Google Voice (3)
  • Google Wave (5)
  • Greasemonkey (18)
  • iGoogle (33)
  • Image Search (47)
  • InOut (20)
  • Knowledge (7)
  • Mobile (77)
  • Music (5)
  • Nostalgia (7)
  • OneBox (18)
  • orkut (5)
  • Page Creator (3)
  • Picasa (4)
  • Picasa Web Albums (25)
  • PlusBox (1)
  • Security (9)
  • Social (56)
  • Software (4)
  • Spam (3)
  • Tips (57)
  • Universal Search (4)
  • User interface (82)
  • Visualization (11)
  • Voice Search (4)
  • Web History (3)
  • Web Search (220)
  • Webmasters (8)
  • Yahoo (8)
  • Yahoo Pipes (2)
  • YouTube (91)

Blog Archive

  • ►  2012 (72)
    • ►  April (5)
    • ►  March (22)
    • ►  February (20)
    • ►  January (25)
  • ▼  2011 (428)
    • ►  December (28)
    • ►  November (40)
    • ►  October (37)
    • ►  September (31)
    • ►  August (41)
    • ►  July (42)
    • ▼  June (48)
      • Google Calendar's Design Refresh
      • A New Interface for Google Search Results Pages
      • People Widget and Other New Gmail Features
      • More Free Storage in Picasa Web for Google+ Users
      • The Google+ Bar
      • Google Takeout
      • Google Swiffy Converts Flash to HTML5
      • More About Google+ Hangouts
      • Google's New Interfaces
      • The Google+ Project
      • FTC's Google Probe
      • Gmail's New Inbox Styles
      • A New Google Homepage Experiment
      • Find Similar Images from a Site
      • Google's Experimental Black Navigation Bar
      • Enable Google Toolbar in Firefox 5
      • YouTube Tests a Black Player
      • How to Use Google Music on an iPad or iPhone
      • A Chrome Extension for Google Music
      • Box.net Integrates with Google Docs
      • Chrome 14 Blocks Insecure JavaScript
      • Mobile Gmail Adds "Pull Down to Refresh"
      • Google Translate Supports 5 Indic Languages
      • Google's New Currency Converter
      • Google's Gay Rainbow
      • Google Docs Tests Offline Support, Powered by HTML5
      • Google Could Add Face Recognition to Google Profiles
      • Chromification of the Operating System
      • Google Tests a New Interface
      • Print Preview in Google Chrome 13
      • Google's Lists of Related Searches
      • Google Tests New Search Snippets UIs
      • My Maps Becomes My Places
      • Google Instant for Image Search
      • Google Adds Voice Search, Visual Search and Result...
      • YouTube's Pages for Blogs, Now Available
      • Google Experiments with Removing URLs from Search ...
      • Chrome Shifts Into a New Gear
      • Checkboxes are Back in Google Docs
      • Better Embedding Code for Google +1 Buttons
      • Google Discontinues Its First Specialized Search E...
      • Google's IPv6 Test
      • YouTube's Pages for Blogs
      • More Pictures in Google Search
      • Creative Commons Videos on YouTube
      • YouTube Reactions
      • Superstars and Nested Labels, Now Standard Gmail F...
      • Google +1 Button for Websites
    • ►  May (33)
    • ►  April (26)
    • ►  March (38)
    • ►  February (34)
    • ►  January (30)
  • ►  2010 (16)
    • ►  January (16)
  • ►  2009 (479)
    • ►  December (35)
    • ►  November (35)
    • ►  October (38)
    • ►  September (43)
    • ►  August (34)
    • ►  July (33)
    • ►  June (40)
    • ►  May (47)
    • ►  April (47)
    • ►  March (46)
    • ►  February (37)
    • ►  January (44)
  • ►  2008 (505)
    • ►  December (35)
    • ►  November (30)
    • ►  October (43)
    • ►  September (44)
    • ►  August (39)
    • ►  July (54)
    • ►  June (45)
    • ►  May (51)
    • ►  April (63)
    • ►  March (64)
    • ►  February (37)
Powered by Blogger.

About Me

Unknown
View my complete profile