Not Everything has to be done Server-side

Here is a little JavaScript trick I did to randomly include LeanPub embed (e.g., like the one in the right sidebar).

  var slugs=['rapid-prototyping-with-js','ohmyjs'];
  var index =Math.round(Math.random());
  jQuery('#leanpub').html('<iframe width="188" height="400" src="'+slugs[index]+'/embed" frameborder="0" allowtransparency="true"></iframe>');});
<div id="leanpub"></div>

Not everything has to be done server-side! The added benefit of this snippet is that it loads  the embed after the rest of the page (thanks to jQuery(document).ready wrapper). This dramatically reduces website loading speed (in my case 0.5-2s), because an iframe generation is one of the most time consuming browser operations.

To use it with your LeanPub books just replace slugs with your books’ ones in the array, and paste into HTML page (or WordPress widget like I did). In case you have more than two books, multiple


by the number of books, e.g. for 10 books:



Best Regards,
Azat Mardan
Microsoft MVP | Book and Course Author | Software Engineering Leader
Azat Mardan avatar
To contact Azat, the main author of this blog, submit the contact form or schedule a call at and we can go over your bugs, questions and career.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.