Showing posts with label yahoo. Show all posts
Showing posts with label yahoo. Show all posts

November 07, 2009

On demand CSS and JS minimization (Java/PHP)

In web development CSS and JS play a very important role but at the same time, if you don't give proper attention, you may make your pages load really slow. I'm a yahoo fan for the standards and open technologies they have come up for the web. If you are a web developer, i strongly recommend these Exception Performance Blog and High performance websites.

Recently in my current work i'd to deal with a requirement where we had a couple of common JS libraries and some common CSS files along with some custom JS and CSS per user too. If you read the above two links, you must be thinking about JS and CSS compression for each of these files. There is an issue though, you will be hitting your server multiple times for each of these files. Since its common for a sufficiently large project to have multiple JS and CSS files, you've to make a choice between combining all the code into very few files vs keeping individual application logic separate. Well i decided to keep them separate :) This may sound absurd, but here is the learning from Y! days that helped me, i decided to not only load them in one go, but as well compress them. Thanks to YUICompressor (it was easy to adapt since its java based). As far as compression performance is concerned, once you compress it, you can always keep it cached for future transmissions. Some data on the performance:

JS - fairly complex (extjs based OO JS) - 1.4 MB - 532 msec - compression achieved 56%
CSS - fairly complex - 1.1 MB - 328 msec - compression achieved 52%

Now depending on the complexity of these source files, the compression might differ, but i'm confident it should not vary way too much from what i've mentioned above.

In our case, we had strict performance requirements to serve most of the requests in sub msecs, so we decided to go the caching way, otherwise i don't think on the fly compression of JS/CSS using YUICompressor is any bad (looking at the numbers above). Below is the code for the portion that does compression (again, its not mine, credit goes to the creators of YUICompressor, i just stripped this piece for my purpose)

JavaScriptCompressor compressor = new JavaScriptCompressor(
    new FileReader("original.js"), new ErrorHandler());
  StringWriter out = new StringWriter("new.js");
  int linebreakpos = 80;
  boolean munge = true, verbose = false, preserveAllSemiColons = false, disableOptimizations = false;
  compressor.compress(out, linebreakpos, munge, verbose,
    preserveAllSemiColons, disableOptimizations);
class ErrorHandler implements ErrorReporter {

  public void warning(String message, String sourceName, int line,
    String lineSource, int lineOffset) {
   if (line < 0) {
    System.err.println("\n[WARNING] " + message);
   } else {
    System.err.println("\n[WARNING] " + line + ':' + lineOffset
      + ':' + message);
   }
  }

  public void error(String message, String sourceName, int line,
    String lineSource, int lineOffset) {
   if (line < 0) {
    System.err.println("\n[ERROR] " + message);
   } else {
    System.err.println("\n[ERROR] " + line + ':' + lineOffset + ':'
      + message);
   }
  }

  public EvaluatorException runtimeError(String message,
    String sourceName, int line, String lineSource, int lineOffset) {
   error(message, sourceName, line, lineSource, lineOffset);
   return new EvaluatorException(message);
  }
 }
CssCompressor compressor = new CssCompressor(new FileReader("original.css"));
  StringWriter out = new StringWriter("new.css");
  int linebreakpos = 80;
  compressor.compress(out, linebreakpos);
One could very well pass a "null" instead of the ErrorHandler instance but make sure that verbose is set to false, else you will get a NPE. So this is just the compression part, what about reducing the number of requests?? Well so i created a servlet that basically takes all the required parameters for loading these static resources and serves them from cache or classpath (well some intelligence required here to avoid serving unwanted stuff but thats pretty straight forward. If you want to know what i did for this, post in comments and i will see if i should post that as well). And just FYI, Y! does similar thing for distributing such files through CDN. Just go to any of the pages on yahoo.com and you would see script urls of the kind
  • http://yui.yahooapis.com/combo?2.8.0r4/build/animation/animation-min.js&2.8.0r4/build/connection/connection-min.js&2.8.0r4/build/container/container-min.js
Now i'm not sure what is done in the backend, but i got this idea looking at their urls. And if you are wondering what if you want to use PHP, there is a similar project called Minify on google code which uses similar concepts borrowed from Y!'s guidelines. That's it for now... more to come!! :-)

July 25, 2009

One week in a call center...

When i told my friends where i was going to join next from Y!, questions like below came up:

  1. Ain't that a BPO, hold on, a call center?

  2. What are you going to do there?

  3. Are you out of your mind?

  4. What the ...?

  5. Yada, yada, yada...


I knew this would come, but when i explained to them what organization in the company i was joining and what my roles and responsibilities would be there, they calmed down with a sigh of relief. Thanks guys for getting concerned so much. This decision wasn't easy to make, but knowing few things like getting to work with my previous manager in Oracle(ST), the work itself, the responsibilities and challenges that it offered; it was easy to say good-bye to Y! for this round. So how did it go in the first week? Well, i would say pretty well; i did face some "on the face" issues but i was already expecting them.

BPO culture is totally different. Every day is a challenge for the call center folks. The cubicles are very close by. People sit close; yet are always talking to some stranger on the other side of the phone. Entire floor is divided into multiple "bays" as they call it dedicated to a particular "account" or "process" and at any moment of the day/night, only a few bays are working (different "account"s/"process"es have different working times depending on the timezone of the customers they serve to). There seems so much "life" in their area when they are working: always chatty, laughing, creating applauds. And at the end of their schedules, you should see them cheering up for each other that they survived yet another tense day for their customers. I don't know about you, but next time i'm going to call to Airtel/Vodafone or any other service provider; i will probably be more gentle in talking to them. After all these guys are also human and they are trying to help us with someone else's fault. Its just human to think that they deserve a better interaction than what they generally get from a p***ed customer.

There are strict processes and rules and guidelines that every employee has to follow. Frankly speaking i was taken aback when HR told me i need to wear formals on weekdays. I also learned that my phone won't be allowed because it had camera. Thankfully i didn't have any storage capability on the phone, that would have been another reason to bar me. Well well well. I can take the phone thing in the spirit of data protection, but the dress code i won't survive. Thankfully when i took up this issue with my senior executives, they said, its ok to wear casuals and jeans for us and i was relieved. There is strict frisking at every entrance. First day it felt like a big pain but now with time it feels really funny raising your hands for the frisking with the metal detector [:D]. I've been told we will be moving to a separate area specially for our organization and there we will have separate rules (created and managed by us only not like the BPO guys); and i'm looking forward to the next month, when all this is expected to happen.

There is a cafeteria at the top floor of my building and food is average. Thankfully there are options for fast food(Chinese, South Indian, Bergers, Sandwiches etc.), regular meal and a tea/coffee shop as well. The meals are not so good and i've been surviving on the dosas and sandwiches. Next week onwards i will be trying out the pyramid cafeteria nearby (definitely a better option, i would say). Its just about time to finalize a routine that would work the best; i'm still exploring.

The gym is of not so standard though they have a trainer. I would say its good enough for the BPO company as they stand today (just like any other business, they have also had bruises in these recessionary times). I've decided to enrol myself to the FitnessOne gym on personal expenses. I will be more comfortable there for sure. This brings another time management challenge, but i'm confident i should be able to make it.

Coming to the work, i feel much satisfied and convinced that i'm a critical part of the organization and have more responsibilities to deliver on the expectations of my organization. There are quite many things to do and its the "my" thing feeling, that will keep me driving for quite sometime to come. This week i was more like trying to settle down but the work has started now. Going forward, you will hear more on the work side (as updates from the call center [:)]). So keep watching this space...

July 19, 2009

bY!e ...

Ahh, time flies by... isn’t it? This friday I completed my 1 year 11 days in Y! and sadly that was my last day as well (at least for this round). I’m moving to a (not-so) startup this Monday for new adventures. It was a tough decision to make but few not-so-good events triggered it and made easier to go through as well. Many good things happened as well in this 1 year tenure that i will cheer for quite sometime to come: Y! Open Hack day, Internal Hack days, Oozie, Office Gym and FitnessOne (lost some 12kgs since feb), awesome cafeteria food and breakout area fruits/snacks, cool and funky work environment and needless to say smart people to work with on interesting challenges for the internet. I've learned from fellow Y!s and would miss few of them for sure. Best of luck Y! and Y!s; I promise to be back with blast (may be not in immediate near future but some longer future for sure).

I'm all geared up and excited for the new challenges. More as it happens...

Related posts:

  1. Thought of the day

  2. Being a Y!...

  3. Open Hack 2009 Concludes

May 28, 2009

Thought of the day

Less than 1 year, 2 cubicles, 3 teams, 4th project, 5 managers, 6 Y! tees, -7kgs (thanks to Y!Gym) - Thats my Y! story until now

April 12, 2009

Being a Y! ...

Y'day i was really happy. For the first time in last 10+ months, i thought man, its good to be a Yahoo! So what do you get being a Y!, here you go with the top five:

  • Smart and great people to work with on interesting challenges that change lives of billions of users on the internet

  • Cool ambiance and friendly and funky work environment

  • Free coffee, tea, snacks, fruits and almost free lunches (and i must confess i've not found such good food in my last 4 years of industry experience elsewhere). Frequent gifts (specially Tees for any and every occassion in the company). I've a number of them now and have stopped buying from malls. :D

  • Free FitnessOne gym membership (apart from the in-house gym and trainer in the office)

  • A respect in the developer community for being an Y! and opportunity to explore your different skills within the company for the company. Y! organizes so many things internally and externally, if you are active, you get to see a lot and won't have time to kill idle.


I really felt classy today in the gym. :D I was sharing gym floor with couple of models who were also working out in the same gym. For a moment, i thanked Y! and was too happy :-) i also hit my first target today 2kms in 10mins, tomorrow i'm going to Pande (my office gym trainer) and hit him with the results :D So, Yahooooooo!!

February 15, 2009

Open Hack 2009 concludes


Wow.. what an event!!! I had amazing last two days. Thanks to all who joined us at the event. The excitement that all the participants showed was awesome. One hacker came to me and i could see his desperation. He was ready to pay "any" amount of money right way for a live windows hosting, all he wanted was an immediate activation. I hope atleast one of my suggested providers were able to help him. There were people hacking on maps, local, BOSS, fireeagle, messenger and what not. Few students even had a hardware hack using a h/w called Sun Spot (aah, is the name right?). Free food, tea/coffee, cold drinks, beer and redbulls.. awesome was the only word in air! Most of the hackers were up whole night to get their ideas up and running, what a tempo!

It was really special one for me too. More so because i had few of my "very good" friends hacking on their ideas as well and we all had an awesome time. Last two days passed without any knowledge(we slept a little at odd hours) and now i can only long for more of that excitement and fun. Thank you Y!, we rock and i'm looking forward to the next blast...

See list of the hacks that were developed for this hackday (within 24 hr hackathon!!!).
See pics

January 20, 2009

Up and running on a new rootshell.be a/c

So few of my friends are planning to attend Y! India hack day scheduled on 14-15th Feb 2009. They just requested a free rootshell.be a/c and thanks to the guys there, they had a free a/c to play with within few hours (Thanks to Xavier and his team at rootshell.be again).

We hit a small problem while hosting our application there. First of all the files we created were not having the right access permissions. Second, rootshell has default configurations to append a little tracking scripts from google to every page that is served from its servers. Now we had problem with this because YAP (Y! application platform) tries to validate a domain by fetching a static file uploaded with some specific content onto the target server. We were getting screwed here because of that small tracking script. This is how we resolved the two issues.

  1. All files in ${HOME}/html folder were given 755 permissions so that apache could read and execute them (umm well most of their stuff is going to be dynamic, so uhh you know...).

  2. We added a .htaccess file in ${HOME}/html folder to change some of the default settings. The portion that helped us get rid of the tracking script is as follows:

    LayoutMerge Off
    LayoutDefaultHandlers Off

  3. Provide 755 permission to .htaccess file as well so that apache can read it. Else it will be throwing "403 forbidden" errors



But, this is just part of the .htaccess configuration. If you are writing a .htaccess file, it is recommended that you search on Y! Search for tutorials on what all you should take care of. That's all for now. Will keep updating as we go on.

BTW everybody is invited to the Y! India hack day. There are limited seats and final participation will be by confirmed invitation only. So what are you waiting for, go book your seat before they are gone... :-)