Tagged: JavaScript

How to make your website serve pages faster?

I made this list for CNN but it might be useful for any website owner.

CNN source code message

HTML source code at CNN.com has a hidden message. CNN Labs team asks for more ways to speed up their website.

I am always on the lookout for junk-serving domain names that I can add to my OS hosts file and CNN provided a number of them. Browsing through their source code, I found a message asking for ideas to improve site speeds. The CNN Labs team has already implemented several speed improvement techniques such as CDN, DNS prefetching, aysnc loads, and code minifying, and were interested in anything developers curious enough to look into their code could provide. Here are a few that I came up with:

  • Load HTML first. Everything else should be loaded afterwards. When CSS and JS are loaded along with HTML, they will block the display of the page content for at least one or two seconds. To do it properly, pre-press static HTML pages from your CMS and serve those static HTML pages to your visitors. Don’t put your HTML content in a database and serve them using a server-side script every time some one requests an article. Static HTML pages are served without any server-side processing latency. Like an image file, static pages are copied to the browser without any processing. They will not be parsed and interpreted like a PHP or ASPX script. (Pre-compiled scripts may be faster but not as fast as a simple file copy to an output response stream.) Use server-side scripts for what they were originally meant for – really dynamic stuff such as Ajax requests, database searches and changes, handling live data and processing user input.
  • Lazy-load Javascript files, CSS stylsheets, images and videos using Javascript code in the static HTML pages. (My unreleased CMS does these two things already – check out www.vsubhash.com. While this CMS is targeted at people with personal websites, these two ideas can reduce waiting times for any kind of website.)
  • Don’t use custom fonts that get automatically downloaded from your website or even the Google fonts repository. (CNN uses its own “CNN” font.) Use a universal stylesheet instead. Browsers can render web pages faster if they can use fonts already installed on the device. Does that make your webpages appear differently on different devices? Sweet mother of God! How will you survive? Really? No, sir, we don’t think much about your corporate/branding font. It barely registers on our minds. You are serving English text to an English audience. You don’t need a custom font. Custom fonts are meant for languages that don’t have universal device support or if the text is in a non-Unicode non-standard encoding tied to some legacy font. The need to display bar codes on a shopping site is a good use-case for a custom font. Emojis are not. Your EOT font download is likely to get stuck with all the other junk your page is downloading simultaneously. The visitor sees blanks everywhere in place of text, wondering what has gone wrong. Is that good for your corporate image? Don’t shock the user. Please learn about the Principle of Least Surprise (PLS).
  • Don’t think people with enough bandwidth will have no problem. Whether you are on a PC or a mobile device (good Linux computers exempted), there are hundreds of processes that are forever talking to base and downloading/uploading files and data.  Your webpage is competing with that and other tabs already opened in the browser. (Google’s policy states that Android will be talking to base, even if no app is running, even if it is in sleep mode, even if you have turned off wireless… So, imagine the situation when the device is being actively used.)
  • Don’t use images when the same effect can be achieved by CSS. But don’t use a CSS or Javascript framework when a simple image would do.
  • Don’t use a third-party CMS or big Javascript frameworks for your high-traffic website. This kind of software suffer from code bloat as CMS developers try to cram more features or try to make certain features work in all situations. Write your own CMS with custom Javascript and CSS optimized for your website. Maximum control & efficiency should be the goal. (CNN web pages, typical of off-the-shef CMS-driven websites, contain a ton of JS and CSS and very little HTML.) Another problem with popular CMS programs are that site admins well-versed with them are not easy to find. Even if you do find them, it may be difficult for them to determine what a piece of code is doing. You eventually end up hiring developers who can add extra or customized functionality over the CMS-generated Javascript and CSS. Good developers will write their own code but many will resort to using more third-party CMS plugins. Over time, the code bloat will get beyond control. Very few developers in the Web team will be familiar with the site’s code and be able to troubleshoot effectively.
  • When you use ad networks, it is inevitable that you lose some control. However, you:
    • can load their script asynchronously (as CNN has already done).
    • ensure that their code is within limits. Many ad networks download a ton of (the same) Javascript libraries to do the simplest of things.
    • do not use more than one ad network in one page serving. You can rotate different providers on different browser requests. If you hit so many third-party sites for one request, as CNN does, what efficiency will you achieve?
  • Don’t use autoplay videos, even if you are a TV news channel. Are you misrepresenting video plays to advertisers? What? Top tech companies do it as well? Well, it is not a matter of just ethics but money too. Be assured that autoplay videos are a waste of bandwidth when the visitor just wants to read your article or is already listening to music. Even with the inflated statistics, you will still lose money… over time.
  • Why use a third-party service to serve related articles from your own site? Ensure that your articles are tagged and categorized appropriately and serve their links on the sidebar, ordered by date and/or popularity. Ensure that this “related” stuff is not part of the static HTML churned out by your CMS. Lazy-load related content as well.
  • Limit the number of redirects in the links you post online. CNN links on Twitter pass through a maze of domains before settling down. These hops are time-consuming because they are on a https connection. Here is a list of redirects for one of their links (https://cnn.it/2DtZSme).
    • t.co (Twitter) to cnn.it
    • cnn.it to bit.ly
    • bit.ly to trib.al
    • trib.al to www․cnn.com
    • www․cnn.com to edition.cnn.com
  • Is your website accessibility-friendly? When you create an accessible website, you create a fast website by default. If you see more CSS+JS than HTML in a ‘View Source’, then your site is not accessible. It is not search engine-friendly either.
  • Don’t use pages that automatically reload. Are you a moron? (Not you, sir/madam, but I can list a dozen websites, a prominent news aggregation site among them, that do this without shame and this question is rhetorically addressed to them.) Use Ajax unobtrusively to change only the updated content.
  • Understand the principle behind Ajax. You display a page first and then use Ajax to inject data into it without reloading. Gmail does this in reverse. It will make you wait while it loads several megabytes of XML data, containing all your emails, before it displays your inbox – totally defeating the idea behind XML requests. Load what is not needed, not everything from the beginning of time.
  • Don’t use social media plugins as-is-where-is. They usually block the loading of the page. Study their no-script versions and use your Javascript to generate valid links dynamically.
  • Analytics code increases bloat , reduce the responsiveness of the site and increases bandwidth usage. Do you really need them? There are many free server software that can process server log files and generate insightful visitor stats. Check your CMS or ask your hosting provider. If you need to study click-intensive regions for improving site effectiveness, use them on a temporary basis and get rid of it once you have generated enough data.
  • Don’t think that as Javascript engines are so fast, browsers will have no problem with all the gunk you have included in your webpages. Nah-hah! Javascript engines may claim to be fast but HTML and CSS rendering is still slow. Don’t believe me? Check out my Javascript benchmark test. After that, add network latencies (over which you have no control) to the mix and judge for yourself.
  • Over time, your pages will become overweight and be lethargic. Either give your site a redesign or start afresh. If not, do regular weight trimming. Measure the dry and wet weight of a web page. Is it really worth it? Regular code reviews help identify parts that are no longer required and provide ideas to optimize CSS and JS.

Facebook Posts Deleter updated – Greasemonkey script to delete FB posts one by one

Facebook archives all your posts, photos and videos to optical media, not just HDDs. So, when you tell them to delete your content, do they really delete it from its cold-storage system too? Unlikely. Delete Facebook, if you have one, now.

Facebook Posts Deleter 2016 was a User Script that automatically deleted Facebook posts one by one on the FB “Activity Log” page. You could use this script if you did not trust Facebook to delete the content when you choose that option on its page. One FB user, who sued Facebook, found that deleted content continues to reside on Facebook servers on its distributed content delivery network long after the account has been “deleted” by Facebook.

Like Google/YouTube, Facebook seems to be serving different set of web pages, CSS & JS for different versions of web browsers. This User JavaScript was developed and tested in Firefox 34. Spoof this version with a Firefox add-on. The code is now very simple. There is no start button. It will start deleting posts without warning.

Greasemonkey script to click the “Load More” button of YouTube video pages

YouTube forces its content creators to create lots of videos than is necessary. I have been watching the drawing videos of an artist. She is now posting videos every day, not about drawing but about her everyday activities. In these videos, she posts links to the real drawing videos or tells about them in advance. It’s awful. She is not alone. There are lots of people who seem to be doing this. There was this one guy whose electronics videos I watched a few times. I decided to check what else he had posted. Yikes! A whole lot of useless nothingness videos! I didn’t see them earlier because I always change the filter to “Most popular”.

If content creators stop making such videos, YouTube lets their earnings fall. This is because only the latest videos of subscribed channels are listed when people launch the YouTube app. If a content creator does not produce at least two or three videos per week, it is easy to get hidden by other channels when he/she does release a new video after a long break.

I use bookmarks and the hidden RSS feeds of YouTube. I don’t login and I don’t watch them live. Because of unexplained lag issues, I download the videos and watch them offline on my WDTV device.

When I check the videos pages, only some video thumbnails are listed there. There is a “Load More” button, which needs to be clicked several times to get the full listing. Sometimes the Net connection breaks during this interval and the expansion of the page stops. I need to then refresh the page and then click the button a few times to get to down to where I was. So, I wrote this Greasemonkey script to that for me. I load the video page and the script automatically clicks the button several times, waiting for sometime between each click to let the videos thumbnails.

With this script, I open the videos page to let it roll out. Meanwhile, I browse some other page. By the time I come back to the video page, all the thumbnails are listed.

Greasemonkey JavaScript-based YouTube adblocker and annoyances remover

Watching YouTube online is still impossible for me – the Net connection is still flaky and there are disturbances in the electricity supply. Downloading the videos and playing them offline is still the only option for me. Even then, the YouTube comes with a great deal of annoyances – ads (text and video), autoplay, “Recommended for you” video list, lack of RSS feeds, half-hidden description, YouTube-curated (or censored) “Top Comments”.

I have created several Greasemonkey scripts to deal with YouTube. Recently, I added a few more. Here they are:

The last one is new. It does several things – disables video ads, hides text ads, disables autoplay, deletes “recommended for you” ads.

Disabling video ads was tricky. The current implementation opens the same video URL in another tab and closes the current tab. This is repeated until YouTube relents and loads the original video. This can range anywhere from 2 to 10 reloads, probably. The code also finds the mute button and mutes the ad.

NOTE: I use an old version of Firefox and I spoof a newer but still old version in it. YouTube and other Google sites serve different styles of pages for different browser versions. The above code works with Firefox 42. To make the code work, you can spoof version 42 using the UserAgent Switcher add-on with this UA string.

Mozilla/5.0 (Windows NT 6.2; rv:42) Gecko/20100101 Firefox/42.0

Of course, I will not be publishing the ad-blocking code. YouTube apocalypse is on now. Ad agencies have done to YouTube what they had been doing for decades to newspaper and TV journalism – interfering in content. After CNN decided to launch a crusade against Alex Jones’ YouTube channels, ad agencies are now telling YouTube that their ads should not be playing on “controversial” content. The bottomline now is that videos from big music labels and stars can have all kind of crude/vulgar/unsuitable content but ordinary folk stepping out of the line will have to be immediately “demonetized.” I found one retired nurse, who publishes makeup tutorials, complaining that she never said a bad word or anything controversial but all her videos were demonetized.

Until the said apocalypse, YouTube content creators seem to have been generously paid. When the times were good, YouTube went all over the world asking people to make videos and make tons of money. Now, YouTube’s revenues are down and the first victims are the small and independent content creators who took YouTube’s bait. A million page views earns the creators very little. It is only with off-YouTube marketing deals and paid-promotion that YouTube content creators can make money. I am surprised that that many seemingly intelligent people left their day jobs and became “Youtubers” full time. Even more sad are the legion of retired folks whose savings have been destroyed by Bush and Obama’s zero-interest monetary regime and free-trade policies, and Wall Street’s looting of pension funds and local government funds. There can be no economy without local manufacturing. Selfies and cat videos are not what an advanced economy runs on.

Anyway, I can tolerate text ads. The videos ads are horrible. The “recommended for you” videos are downright creepy. Why are they recommended for me?

Greasemonkey script to display newer comments on YouTube – bypass censorship

Changes comments filter to “Newest first” from “Top comments”

YouTube has been raining on the parade of its content creators with demonetization, censorship and unexplained notifications disablement. Youtube comments are also being censored. The default filter is not “Newest first” or “Oldest first” but “Top comments”. Trolls will eventually game the system. I would rather see unfiltered comments. So, here it is:

A GreaseMonkey script to generate RSS feed links for YouTube channels

Many people use RSS feeds as the primary means to access news and information. RSS is anonymous and does not require you to log in.

Though YouTube generates RSS feeds for its channels, it does not display them (to human visitors) or advertise them (to browser software). If you prefer to subscribe to YouTube videos via RSS, then you have to manually construct the the feed URL for each channel.

I decided to automate the task using this Greasemonkey script. A few seconds after a YouTube video page gets loaded, the Greasemonkey Javascript adds an RSS icon image next to the channel name. The script links the image to the RSS feed of the YouTube channel. (This RSS icon image works seamlessly as it is from Google and is used in its “News” pages.) The Greasemonkey script also adds an RSS link tag to the HTML HEAD section so that browser applications can activate their RSS feed toolbar button.

A YouTube channel listing in the Bamboo RSS feed reader (a Firefox add-on or extension).

RSS provides an easier way to check Youtube channels. All that matters to YouTube is that people see their ads. RSS does not block ads and so no problem. Viewers who rely on subscriptions are likely to miss new but not so fresh videos if they don’t log in regularly. (Such videos get folded/wrapped/hidden as newer videos are published.) YouTube RSS feeds can ensure that viewers are more likely to get to know about the existence of a new video.

And, to use this script, you will need the Greasemonkey add-on in the browser. It can be installed from the Firefox/Seamonkey browser add-on search page (Tools – Add-ons from the main menu).

This article has been submitted to .

How to download & play YouTube videos offline using Subhash Browser app for Android

Youtube videos don’t play in any of my Android devices, that is, in the browsers. I think their Javascript tries to launch the YouTube app and remains stuck there (because I delete/disable all Google apps).

Fortunately, my app has a Javasript script which lets me download the videos as a file for offline viewing.


Download Any YouTube Video From Anywhere 2016 – User JS for Opera 12.x, Firefox and Android

SCREENSHOT-Subhash-Browser-YouTube-Video-DownloadMy Internet connection does not allow me to play videos live. I need to download them first and then play them. I used to use a FireFox extension called Download YouTube as FLV and MP4 for this. However, my primary browser is Opera 12.x. Today, I decided to write a User JS that would provide the same functionality in Opera 12.x. (The Opera browser company does not provide 12x anymore. They sold out and provide a crappy Chrome imitation.) UPDATE: I adapted this script for my Android browser app and also created a Greasemonkey version for Firefox. On Youtube pages, it displays a drop-down list with download options in various formats. On other pages that have inline videos, it adds a download button. (Check http://softwarerecs.stackexchange.com/questions/817/software-to-download-youtube-videos-to-hard-drive/32132#32132)

Facebook Posts Deleter 2016 – User JavaScript for Opera 12.x and Firefox

Clean out your Facebook activity log with Facebook Posts Deleter 2016!

There is a Greasemonkey script called Facebook Timeline Cleaner, which has not been updated and does not work anymore. So, I created my own User JS for Opera and later adapted it for Firefox. I am not wholly satisfied with this script as it uses recursion. But, it does work. See this video. It is extremely gratifying to see Facebook posts get deleted mercilessly.

// ==UserScript==
// @name        Facebook Posts Deleter
// @namespace   com.vsubhash.js.facebook.posts.deleter
// @description Deletes all facebook posts
// @version     1
// @grant       none
// ==/UserScript==
document.addEventListener("DOMContentLoaded", addFacebookPostsDeleteButton, false);
var oMvFbTimeout1, oMvFbTimeout2, oMvFbTimeout3;
function deleteTimelinePosts() {
  var i, j, k;
  if (document.getElementsByClassName("fbTimelineLogStream").length > 0) {  
    // console.error("Found a stream DIV");
    for (n = 0; n < document.getElementsByClassName("fbTimelineLogStream").length; n++) {
      var oStreamDiv = document.getElementsByClassName("fbTimelineLogStream")[n];
      for (i = 0; i < oStreamDiv.getElementsByTagName("div").length; i++) {
        // console.error("Class name of DIV" + oStreamDiv.getElementsByTagName("div")[i].className);
        if ((oStreamDiv.getElementsByTagName("div")[i].className.indexOf("pam") != -1) &&
            (oStreamDiv.getElementsByTagName("div")[i].className.indexOf("uiBoxWhite") != -1) &&
            (oStreamDiv.getElementsByTagName("div")[i].className.indexOf("bottomborder") != -1)) {
          // console.error("Found a post DIV in the stream DIV");      
          var oPostDiv = oStreamDiv.getElementsByTagName("div")[i];
          if (oPostDiv.getElementsByTagName("table").length > 0) {
            if (oPostDiv.getElementsByTagName("table")[0].getElementsByTagName("td").length == 3) {
             // console.error("Found a table in the post DIV");              
              var oCell = oPostDiv.getElementsByTagName("table")[0].getElementsByTagName("td")[2];
              var oCellMenuLink = oCell.getElementsByTagName("div")[0].getElementsByTagName("div")[0].getElementsByTagName("a")[0];
function clickDelete() {
  var oMenuItems = document.getElementsByClassName("__MenuItem");
  for (var i = 0; i < oMenuItems.length; i++) {
    if (oMenuItems[i].getElementsByTagName("a").length > 0) {
      var oMenuItemLink = oMenuItems[i].getElementsByTagName("a")[0];
      if (oMenuItemLink.getAttribute("ajaxify").indexOf("/ajax/timeline/delete/confirm") != -1) {
       // console.error("Ajaxify " + oMenuItemLink.getAttribute("ajaxify"));      
        oMenuItemLink.style.backgroundColor = "orange";
        if (oMvFbTimeout2 != null) { window.clearTimeout(oMvFbTimeout2); }
        oMvFbTimeout2 = window.setTimeout(
          function() { 
            var oForms = document.getElementsByTagName("form");
            for (var j = 0; j < oForms.length; j++) {
              if (oForms[j].getAttribute("action").indexOf("/ajax/timeline/delete") != -1) {
                var oButtons = oForms[j].getElementsByTagName("button");
                for (var k = 0; k < oButtons.length; k++) {
                  if (oButtons[k].textContent.indexOf("Delete Post") != -1) {                    
                    if (oMvFbTimeout3 != null) { window.clearTimeout(oMvFbTimeout3); }
                    oMvFbTimeout3 = window.setTimeout(
                        function() {
                          // console.error("final call");
                          for (var l = 0; l < document.getElementsByTagName("a").length; l++) {                          
                            if ((document.getElementsByTagName("a")[l].getAttribute("action") == "cancel") &&
                                (document.getElementsByTagName("a")[l].className.indexOf("layerCancel") != -1)) {
                              // console.error("final call as");
                              document.getElementsByTagName("a")[l].style.backgroundColor = "orange";
        if (oMvFbTimeout1 != null) { window.clearTimeout(oMvFbTimeout1); }
        oMvFbTimeout1  = window.setTimeout(function () { deleteTimelinePosts() }, 12000);
function addFacebookPostsDeleteButton() {  
  var oBody = document.getElementsByTagName("body")[0];
  var oInjectDiv = document.createElement("div");
  oInjectDiv.setAttribute("style", "position: absolute; top: 0; left: 0; background-color: rgba(50,150,30, 0.5); width: 190px; height: 50px; z-index: 333!important; ");
  oInjectDiv.innerHTML = "<input id='MvDelButton' type='button' value='Delete Facebook Posts' />";    
  oBody.insertBefore(oInjectDiv, oBody.childNodes[0]);
  document.getElementById("MvDelButton").addEventListener("click", deleteTimelinePosts, false);  
}) != -1) {
                var oButtons = oForms[j].getElementsByTagName(

This source is also available at: https://gist.github.com/vsubhash/

[This post was updated in 2016]