<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Instance Of An Object</title>
    <description>Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.
</description>
    <link>http://www.instanceofanobject.com/</link>
    <atom:link href="http://www.instanceofanobject.com/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Mon, 26 Oct 2015 12:14:06 +0000</pubDate>
    <lastBuildDate>Mon, 26 Oct 2015 12:14:06 +0000</lastBuildDate>
    <generator>Jekyll v2.5.3</generator>
    
      <item>
        <title>Go from Multi-Page to a Single-Page Web App</title>
        <description>&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;/h2&gt;
&lt;p&gt;You have your nice classic multi-page web application and you want to move to the new &lt;a href=&quot;https://en.wikipedia.org/wiki/Single-page_application&quot;&gt;Single-Page (SPA)&lt;/a&gt; paradigm.&lt;/p&gt;

&lt;p&gt;I’ll leave the why so and why not to “SPA” to another post.
I’m assuming you’ve made up your mind and that you already chose your technology, lets say &lt;a href=&quot;https://angularjs.org/&quot;&gt;AngularJS 1.x&lt;/a&gt; or &lt;a href=&quot;https://angular.io/&quot;&gt;AngularJS 2.x&lt;/a&gt;, but you’re still asking yourself:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;What skills do I need to have in the team?&lt;/li&gt;
  &lt;li&gt;What should I be aware?&lt;/li&gt;
  &lt;li&gt;From where should I start?&lt;/li&gt;
  &lt;li&gt;What would be the best approach?&lt;/li&gt;
  &lt;li&gt;How do I estimate the necessary time?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I’ve been there several times so I’ve decided to share my experience and hopefully save someone else’s time and patience.&lt;/p&gt;

&lt;h2 id=&quot;train-your-team&quot;&gt;Train your team&lt;/h2&gt;
&lt;p&gt;If I would have to choose the most important thing for the success of this migration process I would say: &lt;strong&gt;Train your team!!&lt;/strong&gt;.&lt;br /&gt;
Really, I can’t stress this enough.&lt;/p&gt;

&lt;p&gt;If your team is not completely aligned regarding knowledge and processes, this will fail, badly.&lt;br /&gt;
The core knowledge needed is not only on AngularJS (or any other framework), you need to have a deep and solid understanding of Javascript itself.&lt;/p&gt;

&lt;p&gt;Here’s my preferred list of resources I usually propose to my teams and trainees:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Books&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.manning.com/books/secrets-of-the-javascript-ninja&quot;&gt;Secrets of the Javascript Ninja&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://shop.oreilly.com/product/9780596517748.do&quot;&gt;Javascript: The good parts&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://shop.oreilly.com/product/9780596802806.do&quot;&gt;High Performance Javascript&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Video content&lt;/strong&gt;&lt;br /&gt;
Search by Angular and Javascript on these sites and you’ll find a lot of awesome material.&lt;br /&gt;
I won’t point to any specific training because they keep putting more up to date content so it’s better if you just search!&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://app.pluralsight.com/library/&quot;&gt;Pluralsight&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://egghead.io/&quot;&gt;Egghead.io&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;define-a-strategy&quot;&gt;Define a strategy&lt;/h2&gt;
&lt;p&gt;In everything we do we should define a strategy, even if it’s a shallow one, something is always better than nothing.&lt;/p&gt;

&lt;p&gt;In this specific case, is very important that you don’t start changing code all over the place otherwise you’ll end up with an uncontrolled amount of regressions and frustration will kill you.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do things incrementally&lt;/strong&gt; and you’ll even be able to keep adding features to your app along side with this migration process.&lt;br /&gt;
This is a very important selling point when you need to do this migration as part of a technical task and the business sees no real added value upfront.&lt;br /&gt;
It’s very important that you don’t stall the new features implementation flow and keep giving them the added value the product owner requested plus the performance boost and user-friendly features a SPA allows.&lt;/p&gt;

&lt;p&gt;Of course, there’s a bit of a compromise here, and you won’t be able to fit as many features in your sprint but don’t stop it completely.&lt;/p&gt;

&lt;p&gt;Here’s the approach I like to follow:&lt;/p&gt;

&lt;h3 id=&quot;phase-1-split-the-controllers&quot;&gt;Phase 1: Split the controllers&lt;/h3&gt;
&lt;p&gt;One good way is to keep the single-page paradigm aside at first and migrate the views, one by one to Angular.&lt;br /&gt;
Doing it like this, the pages will keep being delivered by as usual from server-side but all the dynamic elements will be rendered with Angular. The site will keep on working and some views will be Angular others are legacy code and changing views will still trigger a full page refresh.&lt;/p&gt;

&lt;h4 id=&quot;mvc-in-the-back-end&quot;&gt;MVC in the back-end?&lt;/h4&gt;
&lt;p&gt;During this process, you’ll be “forced” to clean-up your server-side controllers and make new ones that return JSON instead of HTML. These will be the AJAX endpoints of you angular service that will handle all the $http requests.
You’ll end up with one controller method to deliver the HTML view and a bunch of other methods that implement the necessary CRUD.
I advise to prefix all the CRUD routes with /api/…, this will help you isolate the routes that return JSON from the ones that return HTML.&lt;br /&gt;
No pressure, take your time.
Meanwhile, new screens and improvements that you have in the pipeline should be done directly in Angular.&lt;/p&gt;

&lt;h4 id=&quot;no-mvc-in-the-back-end&quot;&gt;No MVC in the back-end?&lt;/h4&gt;
&lt;p&gt;If you’re not using MVC on the back-end, the process should be more or less the same as described above anyway with the exception that you might want to use another technology to handle your AJAX requests.&lt;/p&gt;

&lt;p&gt;Here are some options depending on your server-side technology:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;.Net Framework: &lt;a href=&quot;http://www.asp.net/web-api&quot;&gt;Web API&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;JAVA: &lt;a href=&quot;http://resteasy.jboss.org/&quot;&gt;RESTEasy&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;PHP: &lt;a href=&quot;http://www.slimframework.com/&quot;&gt;Slim&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;…&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The list goes on, and each platform has multiple options; choose your own!&lt;/p&gt;

&lt;h3 id=&quot;phase-2-start-managing-state-with-angular&quot;&gt;Phase 2: Start managing state with Angular&lt;/h3&gt;
&lt;p&gt;This will take you some time to figure out and debug.&lt;br /&gt;
Basically, you’ll need to move all the user state to Angular, more specifically into a separate angular service/factory that will be used by all Angular controllers.&lt;br /&gt;
It’s this mechanism that will allow you later to hit F5 in the browser and still get the needed logged in user information and permissions.&lt;br /&gt;
You achieve this by adding a controller on the server that you can do an AJAX call and retrieve this information.&lt;/p&gt;

&lt;h3 id=&quot;phase-3-add-ng-route&quot;&gt;Phase 3: Add ng-route&lt;/h3&gt;
&lt;p&gt;Once all the views are converted and are able to manage their state, it’s time to add ng-route to the mix.&lt;br /&gt;
It’s not mandatory, but this should ideally be a one shot mission for all views. If all the above is completed, it won’t take you that long.&lt;br /&gt;
What you need to do here is to drop all the controller methods that render HTML leaving only one that delivers the main page.&lt;br /&gt;
Move all your views routing logic to Angular leaving only the API routes on the back-end (if you prefix them like I said above, they will be easy to identify.&lt;/p&gt;

&lt;h3 id=&quot;phase-4-the-login-page&quot;&gt;Phase 4: The login page&lt;/h3&gt;
&lt;p&gt;In all this, I never mentioned the login page and it was on purpose.&lt;br /&gt;
You can leave this one to the end because doing a full page refresh every time you login/logout will be useful to clean up some nasty global and badly written javascript you might have.&lt;br /&gt;
Moving the login page into the single-page paradigm means that you don’t do a form post to login, you do it by ajax request and you need to populate your previously prepared state service (Phase 2).&lt;br /&gt;
You also have to clean this info once you logout or you get a 401 from the server and redirect to the login view.&lt;/p&gt;

&lt;h2 id=&quot;the-pitfalls-list&quot;&gt;The pitfalls list&lt;/h2&gt;
&lt;p&gt;During the process described above, you’ll face a lot of challenges.&lt;br /&gt;
Each time I had to do this exercise I kept aside a list of the problems I encountered and how I solved them.&lt;br /&gt;
Bellow you’ll find this list. I’ll try to keep it up-to-date and you are also welcome to message me if you have other experiences you want to share.&lt;/p&gt;

&lt;h3 id=&quot;pf1-converting-the-page-javascript-file-into-a-controller&quot;&gt;PF1: Converting the page javascript file into a controller&lt;/h3&gt;
&lt;p&gt;Of course, you’re already using javascript in your site, so what should you do with it?&lt;/p&gt;

&lt;p&gt;If you already use &lt;a href=&quot;http://requirejs.org/&quot;&gt;RequireJS&lt;/a&gt; or any other &lt;a href=&quot;http://requirejs.org/docs/whyamd.html&quot;&gt;AMD&lt;/a&gt; mechanism then it’s easy because you already have your dependencies and encapsulation figured out.&lt;br /&gt;
Each &lt;a href=&quot;http://requirejs.org/&quot;&gt;RequireJS&lt;/a&gt; module represents either a &lt;a href=&quot;https://docs.angularjs.org/guide/controller&quot;&gt;Controller&lt;/a&gt; or a &lt;a href=&quot;https://docs.angularjs.org/guide/services&quot;&gt;Factory or Service&lt;/a&gt; in the Angular world so all you need is to slightly change the way you declare it.&lt;/p&gt;

&lt;p&gt;On the other hand, if you didn’t pay the appropriate attention to the way you handle your Javascript then this will be a harder task.&lt;/p&gt;

&lt;p&gt;The time you’ll spend migrating each page into an AngularJS view will greatly depend on how well structured your current Javascript is.&lt;/p&gt;

&lt;h3 id=&quot;pf2-splitting-code-into-factories&quot;&gt;PF2: Splitting code into factories&lt;/h3&gt;
&lt;p&gt;All reusable code should, or better, must be moved into a Factory or Directive.&lt;br /&gt;
Good examples of this are state or data related methods or code for popups that are used in multiple views.&lt;/p&gt;

&lt;h3 id=&quot;pf3-think-when-its-a-good-idea-to-split-functionalities-into-several-modules&quot;&gt;PF3: Think when it’s a good idea to split functionalities into several modules&lt;/h3&gt;
&lt;p&gt;Modules in AngularJS are a great way to encapsulate logic or even to abstract enterprise level logic that can later on be reused in other applications.&lt;br /&gt;
This way you can easily decouple dependencies and reuse the code later on.&lt;br /&gt;
Thinking this ahead is a good idea, it won’t slow you down and will save you big refactorings later.&lt;/p&gt;

&lt;h3 id=&quot;pf4-be-aware-of-library-version-conflicts&quot;&gt;PF4: Be aware of library version conflicts&lt;/h3&gt;
&lt;p&gt;I recall this problem related to jQueryUI based FileUpload widget. We were using this JQueryUI widget that needed a jQueryUI version higher than the rest of our controls.&lt;br /&gt;
I agree this is a bad thing to have as it is, but this was a legacy site and the client had implemented this upload functionality on a separate page and didn’t want to update the other pages.&lt;br /&gt;
All of the sudden, we were overriding one version of JQueryUI with another and breaking the whole site.&lt;/p&gt;

&lt;p&gt;Another similar problem I also had with another site was with JQuery itself. Different versions of JQuery were being loaded by different components.&lt;/p&gt;

&lt;p&gt;In the Multi-Page world, this is a bad practice but hardly a breaking problem, but as we moved to single-page we had a conflict because the main page itself never changes.&lt;/p&gt;

&lt;p&gt;Be aware of this and enforce one single version for your components across the whole application.&lt;/p&gt;

&lt;h3 id=&quot;pf5-jquery-events-bound-to-the-document&quot;&gt;PF5: jQuery events bound to the document&lt;/h3&gt;
&lt;p&gt;This is a JQuery best-practice that will make you lose some time.&lt;br /&gt;
The problem is that, in a multi-page web application, each time you change page, you start on a clean plate.&lt;br /&gt;
In a single-page scenario, the document is always the same, events bound to it will remain there even when the view changes.&lt;/p&gt;

&lt;p&gt;If we come to a view the event binds are set, lets say for a click of a button, moving to another page and coming back will make the events to be bound again resulting in multiple event handlers for the same event.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;click&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;#btnNext&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;br /&gt;
Use ng-click and handle your code in the controller. This is the correct way to do it and should always be the preferred solution.&lt;/p&gt;

&lt;p&gt;Now there might be cases where you want to just postpone conversion to ng-click so here are some temporary solutions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Temporary Solution 1&lt;/strong&gt;&lt;br /&gt;
If the event handler can actually be bound directly to the element… do it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Temporary Solution 2&lt;/strong&gt;&lt;br /&gt;
If we need to make a delegate event handler, wrap each view with a div.&lt;br /&gt;
Move the event handlers from the document to this wrapper div.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Temporary Solution 3&lt;/strong&gt;&lt;br /&gt;
Some times the same view/controller can be used in more than one parent view.&lt;br /&gt;
A good example of this is popups and the correct solution is to wrap them in Directives but, if for some edge reason at the moment you can’t…&lt;/p&gt;

&lt;p&gt;In this case we can’t use the main view wrapper div because it’s not always the same, so for these edge cases we remove the handler before adding it again:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;gotoNextPage&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt; &lt;span class=&quot;cm&quot;&gt;/* do your stuff */&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;off&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;click&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;#btnNext&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;gotoNextPage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;click&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;#btnNext&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;gotoNextPage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Avoid this and any of the above temporary solutions if you can.&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;pf6-jquery-based-controlswidgets-will-be-a-pain-in-the-neck&quot;&gt;PF6: jQuery based controls/widgets will be a pain in the… neck&lt;/h3&gt;
&lt;p&gt;Most of them will fail to work properly, especially due to event-related problems. Reserve some substantial amount of time for this if you use a lot of these things.
Honor mentions to DatePicker, Dialog, jqGrid…&lt;/p&gt;

&lt;p&gt;A lot of alternatives already exist for most of them and you’ll see that wrapping them yourself with a Directive is also usually not a bad alternative.&lt;/p&gt;

&lt;p&gt;So before starting the migration process, identify all your controls that might need to be worked out.&lt;br /&gt;
If you work on them before starting a page migration, you’ll feel much more confident estimating the effort.&lt;/p&gt;

&lt;h3 id=&quot;pf7-the-login-page-is-still-a-separate-page&quot;&gt;PF7: The Login page is still a separate page?&lt;/h3&gt;
&lt;p&gt;This will require a lot of refactoring, rewriting and rethinking.&lt;/p&gt;

&lt;p&gt;Here’s a small list of pain-points:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hiding the menus and everything else while you’re in the login page&lt;/li&gt;
  &lt;li&gt;Correctly redirecting/refreshing the view when you login/logout&lt;/li&gt;
  &lt;li&gt;Handling the session information when you login/logout and press F5
    &lt;ul&gt;
      &lt;li&gt;Rethink everything related to the session data that was being handled server-side like user information, authorization, contextual data, etc…&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Security, Some views will need to be requested from the server without security validation
    &lt;ul&gt;
      &lt;li&gt;The main change in the paradigm will be that you really need to stop concerning about hiding pages from the user. Your main concern is to secure data, not the HTML and data is still coming and going to the server, secure it there!&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Make sure that all the state is rebuilt client-side if the user presses F5.
    &lt;ul&gt;
      &lt;li&gt;This often requires a separate AJAX call to get the user extra information based on the cookie that you already have.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Move code into a security factory
    &lt;ul&gt;
      &lt;li&gt;Make sure all this code is “grouped” in a single reusable factory that is shared across all views.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;pf8-slowly-start-to-get-rid-of-all-jquery-selectors&quot;&gt;PF8: Slowly start to get rid of all jQuery selectors&lt;/h3&gt;
&lt;p&gt;This is kind of the end of the line for me. When you have the view fully working but jQuery is still being used inside your Angular Controllers.&lt;br /&gt;
Take the extra time to get rid of them. You should not have any jQuery selector inside a Controller. Either replace them with native Directives and Services or create your own.&lt;/p&gt;

&lt;p&gt;Things like &lt;code&gt;$.ajax({})&lt;/code&gt; or &lt;code&gt;$(&#39;#mybutton&#39;).on(&#39;click&#39;, function(){});&lt;/code&gt; must be banned from your code and replaced by &lt;a href=&quot;https://docs.angularjs.org/api/ng/service/$http&quot;&gt;$http&lt;/a&gt; and &lt;a href=&quot;https://docs.angularjs.org/api/ngTouch/directive/ngClick&quot;&gt;ngClick&lt;/a&gt; respectively.&lt;/p&gt;

&lt;h2 id=&quot;final-notes&quot;&gt;Final notes&lt;/h2&gt;
&lt;p&gt;I’m not addressing any migration considerations here specific to &lt;a href=&quot;https://angular.io/&quot;&gt;Angular 2.0&lt;/a&gt; but, apart from syntax changes, the overall considerations remain the same.&lt;/p&gt;

&lt;p&gt;This article was based on my personal experience and I’m sure many other challenges are missing here. If you happen to have something to add, please drop me a line and I’ll be happy to enrich this knowledge base.&lt;/p&gt;

&lt;p&gt;I’m a regular contributor on &lt;a href=&quot;http://www.experts-exchange.com/members/AlexCode.html&quot;&gt;Experts-Exchange&lt;/a&gt; and recently I’ve also &lt;a href=&quot;http://www.experts-exchange.com//questions/28712820/Adopting-AngularJS-in-existing-web-app-Struts-Tomcat.html&quot;&gt;answered a question regarding this topic&lt;/a&gt;.&lt;/p&gt;

</description>
        <pubDate>Thu, 22 Oct 2015 00:00:00 +0000</pubDate>
        <link>http://www.instanceofanobject.com/blog/2015/10/22/from-multi-page-to-single-page.html</link>
        <guid isPermaLink="true">http://www.instanceofanobject.com/blog/2015/10/22/from-multi-page-to-single-page.html</guid>
        
        <category>angularjs</category>
        
        <category>web development</category>
        
        <category>jquery</category>
        
        <category>spa</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>Verify country Google block</title>
        <description>&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;/h2&gt;
&lt;p&gt;Countries like &lt;a href=&quot;https://en.wikipedia.org/wiki/Websites_blocked_in_mainland_China&quot;&gt;China block web traffic from certain domains&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;so-what&quot;&gt;So what?&lt;/h2&gt;
&lt;p&gt;So what if our website depends on some Google API and we don’t want it to break if it’s not available?&lt;/p&gt;

&lt;p&gt;There are two main approaches to try to by-pass this:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Resolving the Country by the request IP&lt;/li&gt;
  &lt;li&gt;Same as above but directly querying an IP database&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are valid options as long as the IP gets well resolved, but nothing actually keeps you from:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;blocking users that might not be affected by the content blockage&lt;/li&gt;
  &lt;li&gt;taking a bad decision if the IP country is unknown&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also these API’s have some usage thresholds and PRO subscriptions can become expensive.&lt;/p&gt;

&lt;h2 id=&quot;test-the-functionality-instead-of-the-country&quot;&gt;Test the functionality instead of the country!&lt;/h2&gt;

&lt;p&gt;Don’t bother trying to identify the country your using is accessing from, try to verify 
if Google is available instead by grabbing a resource that is hosted under a Google domain or sub-domain!&lt;/p&gt;

&lt;p&gt;For instance, &lt;a href=&quot;https://www.google.com/drive/&quot;&gt;Google Drive&lt;/a&gt; lets us store images and make them publically available.&lt;br /&gt;
If we try to access this image from our website and the load fails, then we are sure that the content is blocked!&lt;/p&gt;

&lt;h2 id=&quot;configuring-google-drive&quot;&gt;Configuring Google Drive&lt;/h2&gt;
&lt;p&gt;You can point to an image shared in Google Drive, but there’s a small “trick” that you need to be aware of.&lt;/p&gt;

&lt;p&gt;By default, a shared image URL looks like the following (fake link):&lt;br /&gt;
&lt;code&gt;
https://drive.google.com/file/d/xxxxxxxxxxxxxxxxxxxxxxxxxxxx/view?pli=1
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The problem is that this kind of link will open your file in Google Drive viewer which is useless for us.&lt;br /&gt;
To get a pointer to the image directly we need to use a slightly different URL structure:
&lt;code&gt;
https://drive.google.com/uc?id=xxxxxxxxxxxxxxxxxxxxxxxxxxxx
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The id argument must be exactly the same as the represented by xxxxxxxxxxxxxxxxxxxxxxxxxxxx in the previous link&lt;/p&gt;

&lt;h2 id=&quot;javascript&quot;&gt;Javascript&lt;/h2&gt;
&lt;p&gt;Bellow is the code you must use in your pages:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getElementsByTagName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;body&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
       	&lt;span class=&quot;nx&quot;&gt;img&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;createElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;img&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
       	&lt;span class=&quot;nx&quot;&gt;timestamp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;// a timestamp is added to avoid browser cache&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;img&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;src&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 
        &lt;span class=&quot;s1&quot;&gt;&amp;#39;https://drive.google.com/uc?id=xxxxxxxxxxxxxxxxxxxxxxxxxxxx&amp;amp;_=&amp;#39;&lt;/span&gt; 
        &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;timestamp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    
    &lt;span class=&quot;nx&quot;&gt;img&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onload&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// put your success code here&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;all good!&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    
    &lt;span class=&quot;nx&quot;&gt;img&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;onerror&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt; 
        &lt;span class=&quot;c1&quot;&gt;// put your error code here&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;something went wrong!&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
    
    &lt;span class=&quot;nx&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;appendChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;img&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    
&lt;span class=&quot;p&quot;&gt;})();&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id=&quot;additional-resources&quot;&gt;Additional resources&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Resolve IP to Country APIs and DBs&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://freegeoip.net&quot;&gt;freegeoip&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.maxmind.com&quot;&gt;MaxMind&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.telize.com&quot;&gt;Telize&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Verify China domain blockage&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://viewdns.info/chinesefirewall&quot;&gt;ViewDNS&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Mon, 12 Oct 2015 00:00:00 +0000</pubDate>
        <link>http://www.instanceofanobject.com/blog/2015/10/12/verify-country-google-block.html</link>
        <guid isPermaLink="true">http://www.instanceofanobject.com/blog/2015/10/12/verify-country-google-block.html</guid>
        
        <category>security</category>
        
        <category>web development</category>
        
        <category>google</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>Welcome to Jekyll!</title>
        <description>&lt;p&gt;Some time back, I decided to take my blog out of Blogger.&lt;br /&gt;
I’m not happy with it (I never was actually), so my first idea was to build my own blogging engine as a process for learning a new language.&lt;br /&gt;
And so I did… Too many times :)&lt;br /&gt;
I built it with NodeJS, AngularJS, React… played with several NoSql DB’s, whatever…&lt;br /&gt;
The outcome was always a workable playground but I never had the time to make them good enough for production.&lt;/p&gt;

&lt;p&gt;Meanwhile I also tried existing blogging platforms and now I finally decided to use Jekyll and host it on GitHub.&lt;br /&gt;
I’ll be using this page to document my experience and maybe help someone else.&lt;/p&gt;

&lt;h2 id=&quot;why-jekyll&quot;&gt;Why Jekyll?&lt;/h2&gt;
&lt;p&gt;My first option was &lt;a href=&quot;https://ghost.org/&quot;&gt;Ghost&lt;/a&gt;.&lt;br /&gt;
For whoever doesn’t know about it, &lt;a href=&quot;https://ghost.org/&quot;&gt;Ghost&lt;/a&gt; is a publishing platform based on &lt;a href=&quot;https://nodejs.org/en/&quot;&gt;node.js&lt;/a&gt; and (Express)[http://expressjs.com/]. 
The community is very active and the product features are pretty impressive.&lt;br /&gt;
The problem is that I don’t intend to collaborate or do anything else other than put some words out there. Most of all, I didn’t want to have a database to store static content.&lt;/p&gt;

&lt;p&gt;I want to write, publish and go on with my life.&lt;/p&gt;

&lt;p&gt;That’s when I found &lt;a href=&quot;http://jekyllrb.com/&quot;&gt;Jekyll&lt;/a&gt;.&lt;br /&gt;
To put it correctly, I found it through Github when I was reading about what it supports as publising platforms for project and user pages.&lt;/p&gt;

&lt;p&gt;Jekyll itself is not a blogging platform, is “simply” an HTML generator.&lt;br /&gt;
What you get as a publisher is a set of static HTML files that you can just deploy wherever you want.&lt;br /&gt;
In my case I’m using Github pages and it works just fine.&lt;br /&gt;
If Github turns out not to be the best hosting option, moving everything somewhere else requires no additional effort.&lt;/p&gt;

&lt;h2 id=&quot;plugins&quot;&gt;Plugins&lt;/h2&gt;

&lt;h3 id=&quot;plugins-under-github-pages&quot;&gt;Plugins under GitHub Pages&lt;/h3&gt;
&lt;p&gt;Due to security restrictions, GitHub only supports a (very) limited number of Jekyll plugins.&lt;br /&gt;
Everything else zou might have in zour _plugins folder will be ignored.&lt;/p&gt;

&lt;p&gt;This means that everything works fine on your dev machine but once you deploy do GitHub Pages you’ll loose functionality.&lt;br /&gt;
To solve this I decided to take advantage of git branches and the .nojekyll file.&lt;/p&gt;

&lt;p&gt;What I ended up doing was:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;create a ‘dev’ branch where I have the full Jekyll project&lt;/li&gt;
  &lt;li&gt;empty the ‘master’ branch and copy the contents of the dev branch _site folder&lt;/li&gt;
  &lt;li&gt;add the .nojekyll file in the root of the ‘master’ branch to tell GitHub that this is not a Jekyll site
and that’s it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To automate things I’ve created a deploy.sh bash file in the ‘dev’ branch.&lt;/p&gt;

&lt;p&gt;This is a user site. In case you have a repository site, do the same but for the gh-pages branch.&lt;/p&gt;

&lt;h3 id=&quot;taking-the-most-out-of-tags&quot;&gt;Taking the most out of Tags&lt;/h3&gt;
&lt;p&gt;I like to tag my posts but Jekyll doesn’t support that out of the box.&lt;/p&gt;

&lt;p&gt;I found a nice solution for tags on &lt;a href=&quot;http://charliepark.org/tags-in-jekyll/&quot;&gt;this post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Knowing that Jekyll performs no operation at runtime other that displaying static HTML, tags are no exception. 
This means that if you want to filter by a certain tag, the filtered HTML page have to be rendered at build time, not when the user requests it.&lt;/p&gt;

&lt;p&gt;This is a big paradigm change for most developers but the end, as there are no db queries to be done, the result is a super fast user experience.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/InstanceOfAnObject/InstanceOfAnObject.github.io/blob/dev/_plugins/_tag_gen.rb&quot;&gt;Here’s the link to my repository&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;redirecting-old-blogger-urls&quot;&gt;Redirecting old Blogger URL’s&lt;/h2&gt;
&lt;p&gt;One thing I absolutely had to support is the redirection from the old Blogger URL structure.&lt;br /&gt;
As Jekyll has a different document structure and I also wanted to do some cleanup my previous articles now live in a different URL to which I need to point if someone still points to the old ones.&lt;/p&gt;

&lt;p&gt;To accomplish this I decided to use the 404.html page and add some javascript in there.&lt;br /&gt;
Here’s a small code snippet but you can refer to the whole file &lt;a href=&quot;https://github.com/InstanceOfAnObject/InstanceOfAnObject.github.io/blob/master/404.html#L243-L365&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
	&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;pathname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;c1&quot;&gt;// handle old blogger urls&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/2013/02/fix-ssrs-report-showing-blank-pages.html&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
			&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;href&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/blog/2013/02/19/fix-ssrs-report-showing-blank-pages-when-exporting-to-pdf.html&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/2012/08/windows-7-2008-r2-as-internet-hot-spot.html&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
			&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;location&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;href&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;/blog/2012/08/05/windows-as-internet-hotspot.html&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
			&lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        
        &lt;span class=&quot;cm&quot;&gt;/* ... and so on ... */&lt;/span&gt;
        
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;})();&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id=&quot;using-jekyll-on-cloud9&quot;&gt;Using Jekyll on Cloud9&lt;/h2&gt;
&lt;p&gt;C9 is a great way to edit your GitHub pages Jekyll site.&lt;br /&gt;
Basically you just login with your github account, clone to repository and start editing.&lt;/p&gt;

&lt;p&gt;Here I’ll log the issues and solutions I’ll be facing.&lt;/p&gt;

&lt;h3 id=&quot;start-serving-jekyll-from-c9&quot;&gt;Start serving Jekyll from C9&lt;/h3&gt;
&lt;p&gt;To start serving Jekyll locally we usually use: &lt;em&gt;jekyll serve&lt;/em&gt;&lt;br /&gt;
Under C9 we have to be a bit more specific and specify the host and port:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bash
jekyll serve --host $IP --port $PORT --baseurl &#39;&#39;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If it complains that the port 8080 is already in use, chances are that Apache server took it for himself.&lt;br /&gt;
Execute this to make sure:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bash
lsof -i:8080
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If it’s in fact Apache, execute the following to stop the process:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;bash
sudo /etc/init.d/apache2 stop
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;After this, try starting jekyll again, it will work.&lt;/p&gt;
</description>
        <pubDate>Sun, 05 Jul 2015 14:41:08 +0000</pubDate>
        <link>http://www.instanceofanobject.com/blog/2015/07/05/welcome-to-jekyll.html</link>
        <guid isPermaLink="true">http://www.instanceofanobject.com/blog/2015/07/05/welcome-to-jekyll.html</guid>
        
        <category>jekyll</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>IFrame Orchestrator</title>
        <description>&lt;p&gt;&lt;a href=&quot;https://github.com/InstanceOfAnObject/IFrameOrchestrator&quot;&gt;&lt;img src=&quot;/assets/images/autreplanete_icons/social_icons/png/color/github-color.png&quot; /&gt;Github Repository&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://travis-ci.org/InstanceOfAnObject/IFrameOrchestrator&quot;&gt;&lt;img src=&quot;https://travis-ci.org/InstanceOfAnObject/IFrameOrchestrator.svg?branch=master&quot; alt=&quot;Build Status&quot; /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;description&quot;&gt;Description&lt;/h2&gt;
&lt;p&gt;Orchestrates messages between an IFrame and its parent page, as well as between IFrames on the same page. The Iframes can even reside on different domains!&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/InstanceOfAnObject/IFrameOrchestrator&quot;&gt;Hop on to the Github page&lt;/a&gt; to get everything you need to get started.&lt;/p&gt;

&lt;h2 id=&quot;why&quot;&gt;Why?&lt;/h2&gt;
&lt;p&gt;I realize this looks a bit outdated functionally; after all, who uses IFrames anyway right!?&lt;/p&gt;

&lt;p&gt;Well if you’re asking yourself that question, clearly you’re not a SharePoint developer (neither am I). In SharePoint 2013, Provider Hosted Apps are rendered inside of IFrames that are rendered inside your site.&lt;/p&gt;

&lt;p&gt;If you’re planning to do, lets say, a single-page-app (SPA) to be delivered in this model, you’ll need to interact with the “world” outside your IFrame.&lt;/p&gt;

&lt;h2 id=&quot;what-does-this-do&quot;&gt;What does this do?&lt;/h2&gt;
&lt;p&gt;This tool will allow you to establish a communication pipeline between each IFrame and its parent, easing a lot of pain.&lt;/p&gt;

&lt;p&gt;To take this a bit further, you’ll also be able to pass messages and trigger events between IFrames.&lt;/p&gt;

&lt;h2 id=&quot;where-can-this-be-used&quot;&gt;Where can this be used?&lt;/h2&gt;
&lt;p&gt;The motivation behind this tool was for complex SharePoint Provider Hosted App, but there’s no dependency whatsoever with SharePoint.&lt;/p&gt;
</description>
        <pubDate>Sun, 24 May 2015 00:00:00 +0000</pubDate>
        <link>http://www.instanceofanobject.com/projects/2015/05/24/iframe-orchestrator.html</link>
        <guid isPermaLink="true">http://www.instanceofanobject.com/projects/2015/05/24/iframe-orchestrator.html</guid>
        
        <category>web development</category>
        
        
        <category>projects</category>
        
      </item>
    
      <item>
        <title>CSS Sprite Generator</title>
        <description>&lt;p&gt;&lt;a href=&quot;https://github.com/InstanceOfAnObject/SpriteCreator&quot;&gt;&lt;img src=&quot;/assets/images/autreplanete_icons/social_icons/png/color/github-color.png&quot; /&gt;Github Repository&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;New v2.0&lt;/h2&gt;

&lt;p&gt;I&amp;nbsp; decided to increment the major version of this tool as it implements new core features and actually brakes background compatibility with the previous command line commands.&lt;/p&gt;

&lt;p&gt;So... what&amp;#39;s new?&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;3 Bin Packing algorithms to choose from that optimize the sprite image size&lt;/li&gt;
	&lt;li&gt;New and refactored command line commands to let you automate the generation process&lt;/li&gt;
	&lt;li&gt;Support for inner folders&lt;/li&gt;
	&lt;li&gt;Allow setting the output file names&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Introduction&lt;/h2&gt;

&lt;p&gt;Image Sprites are a very good way to feed your application some images. Basically, it consists of combining a set of images in a larger one and then just caching it. When you need one of the small images, all you have to know are the coordinates of it on the large one. With this technique, you just need to load one image for the entire application and reuse it, instead of loading each image at a time.&lt;/p&gt;

&lt;p&gt;Here, I&amp;#39;ll be covering the implementation with CSS used on WebSites, but you can use this technique wherever you want.&lt;/p&gt;

&lt;h2&gt;Why This?&lt;/h2&gt;

&lt;p&gt;Sure you can Google it and find a lot of matches telling you how to use sprites and CSS but where&amp;#39;s the &amp;quot;no pain&amp;quot; way of building them and their CSS? All of them will tell you to use Photoshop of any other photo editing tool but this will always take a lot of time. That&amp;#39;s when this cute little application comes in. It will generate the sprite image and its CSS in no time, and you can add images later and regenerate it without having to worry about breaking your code!&lt;/p&gt;

&lt;h2&gt;Using the Code&lt;/h2&gt;

&lt;p&gt;On the package, you&amp;#39;ll find a compiled version and its source code.&lt;/p&gt;

&lt;p&gt;Just drop the &lt;em&gt;SpriteCreator.exe&lt;/em&gt; file on the folder that has the images to be included on the sprite and run it. DONE!&lt;/p&gt;

&lt;h3&gt;Assumptions, Limitations and Functionality&lt;/h3&gt;

&lt;ul&gt;
	&lt;li&gt;All image files on the folder will be added to the sprite no matter the size.&lt;/li&gt;
	&lt;li&gt;All the images on the folder will be included on the sprite. &amp;nbsp;&lt;/li&gt;
	&lt;li&gt;Only jpg, jpeg, png &amp;amp; bmp extensions are supported.&lt;/li&gt;
	&lt;li&gt;The name of the images is used on the CSS class name.&lt;/li&gt;
	&lt;li&gt;The spaces on images file name will be replaced with -&lt;/li&gt;
	&lt;li&gt;The result 3 files, one &lt;em&gt;*.png&lt;/em&gt; (the sprite), &lt;em&gt;*.css&lt;/em&gt; and *.html (the demo usage page) where &lt;em&gt;*&lt;/em&gt; is the name you specified or a random GUID.&amp;nbsp;&lt;/li&gt;
	&lt;li&gt;CSS file includes a class that applies the background image to the element&lt;/li&gt;
	&lt;li&gt;Images are ordered using 3 different algorithms (more about them bellow).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Bin Packing Algorithms&lt;/h2&gt;

&lt;p&gt;To optimize the distribution of the images on the sprite I used the code from here:&amp;nbsp; &lt;a href=&quot;http://nuclexframework.codeplex.com/wikipage?title=Nuclex.Game&quot; target=&quot;_blank&quot; title=&quot;Nuclex Game&quot;&gt;Nuclex Game&lt;/a&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;The Bin packing algorithms are very well documented on &lt;a href=&quot;http://nuclexframework.codeplex.com/wikipage?title=Rectangle%20Packing&amp;amp;referringTitle=Nuclex.Game&quot; target=&quot;_blank&quot; title=&quot;Rectangle Packing Documentation&quot;&gt;their page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;All Bin Packing Algorithm credits must be given to these guys that saved me a lot of time by perfectly implementing these three good bin packing algorithms in C#. On my side I only removed the XNA dependencies and replaced them with pure System.Drawing objects.&lt;/p&gt;

&lt;h2&gt;Options&lt;/h2&gt;

&lt;p&gt;This is a console application so you can pass some customization arguments.&lt;/p&gt;

&lt;ol&gt;
	&lt;li&gt;&lt;strong&gt;/h, /?, /help&lt;/strong&gt; :: Help&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;/s&lt;/strong&gt; :: Specify the images source directory path&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;/d&lt;/strong&gt; :: Destination dir path&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;/D&lt;/strong&gt; :: Same as /d but creates the directory if it doesn&amp;#39;t exist&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;/f&lt;/strong&gt; :: Destination file name&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;/F&lt;/strong&gt; :: Same as /f but overrides the files if they already exist&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;/cp&lt;/strong&gt; :: CSS class name prefix&lt;/li&gt;
	&lt;li&gt;&lt;strong&gt;/pl&lt;/strong&gt; :: Specify the Bin Packaging Level (1, 2 (default) or 3)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Ex: &lt;/strong&gt;&lt;em&gt;SpriteCreator.exe&lt;/em&gt; /s Images /F SiteImages /cp &amp;quot;app-ui-&amp;quot;&lt;/p&gt;

&lt;h2&gt;History&lt;/h2&gt;

&lt;ul&gt;
	&lt;li&gt;v1.0 - The very beginning&lt;/li&gt;
	&lt;li&gt;v1.1 - Support for images of different sizes and small improvements.&lt;/li&gt;
	&lt;li&gt;v2.0 - Arguments refactoring and Bin Packing Algorithm usage.&lt;/li&gt;
&lt;/ul&gt;
</description>
        <pubDate>Wed, 18 Dec 2013 12:24:00 +0000</pubDate>
        <link>http://www.instanceofanobject.com/projects/2013/12/18/css-sprite-generator.html</link>
        <guid isPermaLink="true">http://www.instanceofanobject.com/projects/2013/12/18/css-sprite-generator.html</guid>
        
        <category>web development</category>
        
        <category>css</category>
        
        
        <category>projects</category>
        
      </item>
    
      <item>
        <title>Fix SSRS PDF Blank Pages</title>
        <description>&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;/h2&gt;
&lt;p&gt;You’re designing a report on SSRS. Everything looks good until you export it to PDF and you realize that every other page appears blank.&lt;/p&gt;

&lt;p&gt;If this is your problem, read on!&lt;/p&gt;

&lt;h2 id=&quot;the-solution&quot;&gt;The solution&lt;/h2&gt;
&lt;p&gt;The solution is plain simple and rational but if you’re already dealing with a complex report maybe you already switched off your rational part of the brain.&lt;/p&gt;

&lt;p&gt;The idea basically is:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;[Body width] &amp;lt;= [Report Width]-[Report Left Margin]-[Report Right Margin]&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;So do the following:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Go to Report properties&lt;/li&gt;
  &lt;li&gt;Take note of the Width and the left and right margin values&lt;/li&gt;
  &lt;li&gt;Go to the design view and select Body&lt;/li&gt;
  &lt;li&gt;Take note of the Body width&lt;/li&gt;
  &lt;li&gt;Do your math with the above formula, adjust as needed and it should be fine!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cheers!&lt;/p&gt;
</description>
        <pubDate>Tue, 19 Feb 2013 17:29:00 +0000</pubDate>
        <link>http://www.instanceofanobject.com/blog/2013/02/19/fix-ssrs-report-showing-blank-pages-when-exporting-to-pdf.html</link>
        <guid isPermaLink="true">http://www.instanceofanobject.com/blog/2013/02/19/fix-ssrs-report-showing-blank-pages-when-exporting-to-pdf.html</guid>
        
        <category>ssrs</category>
        
        <category>reporting</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>Windows 7/8/2008r2 As Internet Hot Spot!</title>
        <description>&lt;p&gt;Have you ever needed to share your internet connection wirelessly and found that the Windows ways are a bit hard?&lt;/p&gt;

&lt;p&gt;This is vacations time and if you buy a USB pen you probably could use the hability to share your internet with everybody in the house instead of having to share the USB Pen itself!&lt;/p&gt;

&lt;p&gt;Usually you think about a hardware router that supports USB pens but that’s usually too expensive, or at least more expensive than FREE! :)&lt;/p&gt;

&lt;p&gt;The solution is to use &lt;a href=&quot;http://virtualrouter.codeplex.com/&quot; title=&quot;Virtual Router&quot;&gt;Virtual Router&lt;/a&gt;. 
&lt;img src=&quot;/assets/blog/2012-08-05-windows-as-internet-hotspot/screenshot1.jpg&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As you can see the configuration is straight forward:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Set the name of the Network (this is what will be visible to other computers)&lt;/li&gt;
  &lt;li&gt;Set the password used to connect to this network&lt;/li&gt;
  &lt;li&gt;Select the connection you want to share&lt;/li&gt;
  &lt;li&gt;Finally click Start Virtual Router&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So after this, no more sharing your USB pen… Share the connection!!! :) Have fun!&lt;/p&gt;
</description>
        <pubDate>Sun, 05 Aug 2012 00:20:00 +0000</pubDate>
        <link>http://www.instanceofanobject.com/blog/2012/08/05/windows-as-internet-hotspot.html</link>
        <guid isPermaLink="true">http://www.instanceofanobject.com/blog/2012/08/05/windows-as-internet-hotspot.html</guid>
        
        <category>windows</category>
        
        <category>network</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>Include Javascript And CSS On Your MasterPage</title>
        <description>&lt;p&gt;This is a quick one.&lt;/p&gt;

&lt;p&gt;On the web I see a lot of tricks on how to do this but in fact it’s quite easy.&lt;/p&gt;

&lt;h2 id=&quot;the-problem&quot;&gt;The Problem&lt;/h2&gt;

&lt;p&gt;When you reference a script or a css file on your masterpage it takes the relative path of that file according to the MasterPage location. The problem is that the MasterPage isn’t the one that it’s going to be shown, it will be the actual ASPX page the inherits from it.&lt;br /&gt;
This said, if your ASPX files are in other location than the MasterPage then the references script files path won’t be resolved.&lt;/p&gt;

&lt;p&gt;There’s also the problem when your site can either run on a virtual folder or as a site on IIS.&lt;/p&gt;

&lt;h2 id=&quot;the-solution&quot;&gt;The Solution&lt;/h2&gt;

&lt;p&gt;There are a lot of ways to handle this, but most rely on specific ASPX locations.&lt;br /&gt;
I like to have my ASPXs well organized on a convenient way, sometimes in the same folder but most of the times on separated folders.&lt;br /&gt;
I don’t want to be forced to put all pages on the same folder just because of this.&lt;/p&gt;

&lt;p&gt;So the idea is to put all the script and CSS references on the MasterPage &lt;em&gt;&amp;lt;head&amp;gt;&lt;/em&gt;, make use of the server-side tilde (~) and write the correct paths on Page_Init.&lt;/p&gt;

&lt;p&gt;If you need to reference jquery and jqueryUI your MasterPage &lt;em&gt;&amp;lt;head&amp;gt;&lt;/em&gt; should look similar as the following:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;head&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;runat=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;&lt;/span&gt;

 &lt;span class=&quot;nt&quot;&gt;&amp;lt;link&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;href=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;lt;%# ResolveUrl(&amp;quot;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;~/&amp;quot;)&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;css/custom-theme/jquery-ui-1.8.21.custom.css&amp;quot; rel=&amp;quot;stylesheet&amp;quot; type=&amp;quot;text/css&amp;quot; /&amp;gt;

 &lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;lt;%# ResolveUrl(&amp;quot;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;~/&amp;quot;)&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Scripts&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;jquery&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;js&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot; type=&amp;quot;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;javascript&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
 &lt;span class=&quot;nt&quot;&gt;&amp;lt;script &lt;/span&gt;&lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;lt;%# ResolveUrl(&amp;quot;&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;~/&amp;quot;)&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Scripts&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;jquery&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ui&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;js&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot; type=&amp;quot;&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;javascript&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;asp:ContentPlaceHolder&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;ID=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;head&amp;quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;runat=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;server&amp;quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/asp:ContentPlaceHolder&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now, on the MasterPage CodeBehind you should include the following code:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;protected&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;OnLoad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EventArgs&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;k&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OnLoad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;Page&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Header&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DataBind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;DONE!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep in mind that the script and css references paths must be relative to he root of your site.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This way, everywhere the MasterPage is used the paths to the resources will always be correct.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;
</description>
        <pubDate>Thu, 14 Jun 2012 23:24:00 +0000</pubDate>
        <link>http://www.instanceofanobject.com/blog/2012/06/14/include-javascript-and-css-on-your-masterpage.html</link>
        <guid isPermaLink="true">http://www.instanceofanobject.com/blog/2012/06/14/include-javascript-and-css-on-your-masterpage.html</guid>
        
        <category>web development</category>
        
        <category>asp.net</category>
        
        <category>javascript</category>
        
        <category>css</category>
        
        
        <category>blog</category>
        
      </item>
    
      <item>
        <title>Advanced ASP.net Generic Handler</title>
        <description>&lt;p&gt;&lt;a href=&quot;https://github.com/InstanceOfAnObject/ASPnetAdvancedHandler&quot;&gt;&lt;img src=&quot;/assets/images/autreplanete_icons/social_icons/png/color/github-color.png&quot; /&gt;Github Repository&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;disclaimer&quot;&gt;Disclaimer&lt;/h2&gt;
&lt;p&gt;This is a project I did some years back but never took much care maintaining or writing proper automated tests.&lt;br /&gt;
Although this has been used in multiple production applications, I suggest to take your time to understand it properly.&lt;/p&gt;

&lt;p&gt;On &lt;a href=&quot;http://www.codeproject.com/Articles/353260/ASP-NET-Advanced-Generic-Handler-ASHX&quot;&gt;CodeProject&lt;/a&gt; there’s also a nice discusison about this approach over WebAPI.&lt;/p&gt;

&lt;h2 id=&quot;description&quot;&gt;Description&lt;/h2&gt;
&lt;p&gt;In ASP.NET, we have something that is usually overlooked that is called &lt;a href=&quot;https://msdn.microsoft.com/en-us/library/system.web.ihttphandler(v=vs.100).aspx&quot;&gt;Generic Handlers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is an completely worked out Generic Handler that truly knows how to handle your http (AJAX and not) requests.&lt;/p&gt;

&lt;p&gt;For now, for a detailed explanation, please look at the original &lt;a href=&quot;http://www.codeproject.com/Articles/353260/ASP-NET-Advanced-Generic-Handler-ASHX&quot;&gt;CodeProject article&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;why-not-webapi-or-mvc&quot;&gt;Why not WebAPI or MVC?&lt;/h2&gt;
&lt;p&gt;When I wrote this, WebAPI was not available yet.&lt;/p&gt;

&lt;p&gt;Although Generic Handlers still have their meaning, probably you’ll find WebAPI a good match for most of your needs.&lt;/p&gt;

&lt;p&gt;ASP.net MVC Controllers can also be used, specially if you’re already using it in your application.&lt;/p&gt;
</description>
        <pubDate>Sat, 24 Mar 2012 12:24:00 +0000</pubDate>
        <link>http://www.instanceofanobject.com/projects/2012/03/24/advanced-generic-handler-ashx.html</link>
        <guid isPermaLink="true">http://www.instanceofanobject.com/projects/2012/03/24/advanced-generic-handler-ashx.html</guid>
        
        <category>web development</category>
        
        <category>asp.net</category>
        
        
        <category>projects</category>
        
      </item>
    
      <item>
        <title>Advanced Generic Handler ASHX</title>
        <description>&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;

&lt;p&gt;In ASP.net we have something that is usually overlloked that is called Generic Handlers.&lt;br /&gt;
I see a lot o f people using pages to process AJAX requests when we can use this much less expensive endpont.&lt;br /&gt;
This is an completelly worked out Generic Handler that trully knows how to handle your http (AJAX and not) requests.&lt;/p&gt;

&lt;p&gt;Sample code&lt;/p&gt;

&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;

&lt;p&gt;For a long time I used plain Generic Handlers (ASHX files) to handle my AJAX requests but it felt stupid and painful.&lt;br /&gt;
I mean, the functionality was there but the whole process of handling the requests wasn’t straight forward.&lt;br /&gt;
So I made a list of the things I would like to have on and handler:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Standard way to parse the query string&lt;/li&gt;
  &lt;li&gt;Transparently handle multiple methods within the same handler&lt;/li&gt;
  &lt;li&gt;Support methods with multiple typed arguments, not just strings&lt;/li&gt;
  &lt;li&gt;Support Methods that receive lists as an argument&lt;/li&gt;
  &lt;li&gt;Support passing less arguments than the method is expecting (like optional parameters)&lt;/li&gt;
  &lt;li&gt;Transparently reply eather POSTs or GETs&lt;/li&gt;
  &lt;li&gt;Support default object serialization to JSON but still let me override it on each method&lt;/li&gt;
  &lt;li&gt;Return application/json by default but still let me override it on each method&lt;/li&gt;
  &lt;li&gt;Support JQuery $.ajax request&lt;/li&gt;
  &lt;li&gt;Support request by query string (url right on the browser)&lt;/li&gt;
  &lt;li&gt;A way to visualize the methods the hadler supports (like webservices do)&lt;/li&gt;
  &lt;li&gt;Extensible&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that’s it…&lt;/p&gt;

&lt;p&gt;I can tell you in advance that it already does all this and more.&lt;/p&gt;

&lt;h2 id=&quot;using-the-code&quot;&gt;Using The Code&lt;/h2&gt;

&lt;h3 id=&quot;list-the-handler-methods&quot;&gt;List the Handler methods&lt;/h3&gt;
&lt;p&gt;I’ve provided a very basic way of listing the methods the Handler exposes.&lt;br /&gt;
This is specially useful to test if the handler is working correctly (like on webservices)
Do do so just append &lt;em&gt;?help&lt;/em&gt; at the end of the handler URL:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;http://localhost/mydemohandler.ashx?help&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;calling-the-handler-from-the-browser-url&quot;&gt;Calling the Handler from the browser URL&lt;/h3&gt;
&lt;p&gt;Using this handler is very simple:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Create a new Generic Handler&lt;/li&gt;
  &lt;li&gt;Clear everything inside the handler class&lt;/li&gt;
  &lt;li&gt;Inherit from my Handler class&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;DONE! Now you only need to add your methods.&lt;/p&gt;

&lt;p&gt;Lets create a very simple example that receives a name and returns a string (see on the project).&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;MyFirstHandler&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;BaseHandler&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// I don&amp;#39;t bother specifying the return type, it&amp;#39;ll be serialized anyway&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;GreetMe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; 
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;Hello {0}!&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;To call this method through a URL use:&lt;br /&gt;
&lt;em&gt;MyFirstHandler.ashx?method=GreetMe&amp;amp;name=AlexCode&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;ajax-request-using-jquery&quot;&gt;AJAX Request using JQuery&lt;/h3&gt;
&lt;p&gt;If you want to use JQuery AJAX method you just need to know the object the handler is expecting to get.&lt;br /&gt;
On the data property of the $.ajax request you must pass something like:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-json&quot; data-lang=&quot;json&quot;&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
  &lt;span class=&quot;nt&quot;&gt;&amp;quot;method&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;mymethod&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;nt&quot;&gt;&amp;quot;args&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;quot;name&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Alex&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;quot;country&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;CH&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; 
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Be aware that everything is case sensitive!&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ajax&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
 &lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;MyFirstHandler.ashx&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
 &lt;span class=&quot;nx&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;GET&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
 &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;GreetMe&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;args&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;AlexCode&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
 &lt;span class=&quot;nx&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&quot;writing-a-method-that-returns-html&quot;&gt;Writing a method that returns HTML&lt;/h3&gt;
&lt;p&gt;Like I said on my intention points above, I need to have some methods that return whatever I want like HTML, XML, images, files, etc…&lt;br /&gt;
The default behavior of the handler is to return JSON so, by method, we need to explicitly say that we want to handle things our way.&lt;br /&gt;
For that just use these lines anywhere within the method:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;n&quot;&gt;SkipContentTypeEvaluation&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; 
&lt;span class=&quot;n&quot;&gt;SkipDefaultSerialization&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// you can specify the response content type as follows&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ContentType&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;text/html&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Lets see an example on how we could write a method on the handler that returns HTML:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;GiveMeSomeHTML&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;StringBuilder&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;StringBuilder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;My Handler!&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;lt;body&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;This is a HTML page returned from the Handler&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;The text passed was: &amp;quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&amp;quot;&amp;lt;/body&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

 &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ContentType&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&amp;quot;text/html&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;SkipContentTypeEvaluation&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
 &lt;span class=&quot;n&quot;&gt;SkipDefaultSerialization&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

 &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&quot;optional-parameters-and-nullable-types&quot;&gt;Optional Parameters and nullable types&lt;/h3&gt;
&lt;p&gt;All parameters in the methods are optional. If they’re not passed their default value is assigned.&lt;br /&gt;
Also all parameters can be nullable. In this case the default value will be null.&lt;/p&gt;

&lt;p&gt;Please have a look at the attached code sample for more examples.&lt;/p&gt;

&lt;h3 id=&quot;points-of-interest&quot;&gt;Points Of Interest&lt;/h3&gt;

&lt;p&gt;I can say that this handler already saved me a good amount of development and maintenance hours.
Currently all my AJAX requests point to a method on an handler like this.&lt;/p&gt;

&lt;h3 id=&quot;history&quot;&gt;History&lt;/h3&gt;

&lt;p&gt;v1.0 - The first wide open version&lt;br /&gt;
This is a work in progress, I keep improving it regularly.&lt;br /&gt;
I have no doubt that you’ll try to use this in scenarios I haven’t predicted.&lt;br /&gt;
Please send me your requests and desires, I’ll do my best to implement them.&lt;/p&gt;
</description>
        <pubDate>Sat, 24 Mar 2012 01:09:00 +0000</pubDate>
        <link>http://www.instanceofanobject.com/blog/2012/03/24/advanced-generic-handler-ashx.html</link>
        <guid isPermaLink="true">http://www.instanceofanobject.com/blog/2012/03/24/advanced-generic-handler-ashx.html</guid>
        
        <category>web development</category>
        
        <category>asp.net</category>
        
        
        <category>blog</category>
        
      </item>
    
  </channel>
</rss>
