<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>Dev411 Blog: Category ie</title>
  <subtitle type="html">John Wang on Technology</subtitle>
  <id>tag:www.dev411.com,2005:Typo</id>
  <generator uri="http://www.typosphere.org" version="4.0">Typo</generator>
  <link href="http://www.dev411.com/blog/xml/atom/category/feed.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.dev411.com/blog/tag/ie" rel="alternate" type="text/html"/>
  <updated>2007-06-16T12:30:23-05:00</updated>
  <entry>
    <author>
      <name>John Wang</name>
    </author>
    <id>urn:uuid:885f059fcc2a7604158abbca1b8b8be6</id>
    <published>2006-07-25T10:49:00-05:00</published>
    <updated>2007-06-16T12:30:23-05:00</updated>
    <title type="html">Catalyst - Customizing the view to stop IE from caching JSON</title>
    <link href="http://www.dev411.com/blog/2006/07/25/catalyst-customizing-the-view-stop-ie-from-caching-json" rel="alternate" type="text/html"/>
    <category term="json" scheme="http://www.dev411.com/blog/tag/json" label="json"/>
    <category term="catalyst" scheme="http://www.dev411.com/blog/tag/catalyst" label="catalyst"/>
    <category term="ie" scheme="http://www.dev411.com/blog/tag/ie" label="ie"/>
    <category term="ajax" scheme="http://www.dev411.com/blog/tag/ajax" label="ajax"/>
    <summary type="html">&lt;p&gt;Often times you'll want to customize your response specific to the View being used, e.g. setting extra headers. This can be done directly in your View class by creating a &lt;span class="fix"&gt;process&lt;/span&gt; method. All View base classes have a process method defined in &lt;span class="fix"&gt;Catalyst::View&lt;/span&gt; that gets called at rendering time. By adding a &lt;span class="fix"&gt;process&lt;/span&gt; method in your subclass and redispatching to the parent you can do some preliminary processing.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;Often times you'll want to customize your response specific to the View being used, e.g. setting extra headers. This can be done directly in your View class by creating a &lt;span class="fix"&gt;process&lt;/span&gt; method. All View base classes have a process method defined in &lt;span class="fix"&gt;Catalyst::View&lt;/span&gt; that gets called at rendering time. By adding a &lt;span class="fix"&gt;process&lt;/span&gt; method in your subclass and redispatching to the parent you can do some preliminary processing.&lt;/p&gt;

&lt;p&gt;One use is preventing IE from caching JSON responses by setting the Cache-Control and Pragma HTTP response headers. You can do this in the 
application's JSON view as follows:&lt;/p&gt;

&lt;pre&gt;package MyApp::View::JSON;
use strict; use warnings;
use base qw/Catalyst::View::JSON/;

sub process {
  my $self = shift;
  my $c = $_[0];
  $c-&gt;res-&gt;header( 'Cache-Control' =&gt;
    'no-store, no-cache, must-revalidate,'.
    'post-check=0, pre-check=0, max-age=0'
  );
  $c-&gt;res-&gt;header( 'Pragma' =&gt; 'no-cache' );
  $c-&gt;res-&gt;header( 'Expires' =&gt; 'Thu, 01 Jan 1970 00:00:00 GMT' );
  $self-&gt;NEXT::process(@_);
}

1;&lt;/pre&gt;

&lt;p&gt;Your &lt;span class="fix"&gt;process&lt;/span&gt; method will get called, set it's response headers and then use &lt;a href="http://search.cpan.org/~dconway/NEXT-0.60/lib/NEXT.pm" class="fix"&gt;NEXT&lt;/a&gt; to call C::V::JSON's &lt;span class="fix"&gt;process&lt;/span&gt; method.&lt;/p&gt;</content>
  </entry>
  <entry>
    <author>
      <name>John Wang</name>
    </author>
    <id>urn:uuid:829678746bcf7e466ae1a607174ea863</id>
    <published>2006-07-21T10:02:00-05:00</published>
    <updated>2007-11-17T08:08:32-06:00</updated>
    <title type="html">Automated web screen shots with Perl</title>
    <link href="http://www.dev411.com/blog/2006/07/21/automated-web-screen-shots-with-perl" rel="alternate" type="text/html"/>
    <category term="imagemagick" scheme="http://www.dev411.com/blog/tag/imagemagick" label="imagemagick"/>
    <category term="ie" scheme="http://www.dev411.com/blog/tag/ie" label="ie"/>
    <category term="perl" scheme="http://www.dev411.com/blog/tag/perl" label="perl"/>
    <summary type="html">&lt;p&gt;I've been looking for a program that will take full screen shots of web pages even when the web page is larger than the window size on my physical screen, requiring scrolling. This morning I found such a program in Petr &#352;mejkal's &lt;a href="http://search.cpan.org/~psme/Win32-CaptureIE-1.30/CaptureIE.pm" class="fix"&gt;Win32::CaptureIE&lt;/a&gt; when it was mentioned by Displeaser on &lt;a href="http://forums.devshed.com"&gt;DevShed Forums&lt;/a&gt; in the "&lt;a href="http://forums.devshed.com/perl-programming-6/screenshot-of-webpage-370275.html"&gt;Screenshot of webpage&lt;/a&gt;" thread. It uses ImageMagick for image manipulation.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;I've been looking for a program that will take full screen shots of web pages even when the web page is larger than the window size on my physical screen, requiring scrolling. This morning I found such a program in Petr &#352;mejkal's &lt;a href="http://search.cpan.org/~psme/Win32-CaptureIE-1.30/CaptureIE.pm" class="fix"&gt;Win32::CaptureIE&lt;/a&gt; when it was mentioned by Displeaser on &lt;a href="http://forums.devshed.com"&gt;DevShed Forums&lt;/a&gt; in the "&lt;a href="http://forums.devshed.com/perl-programming-6/screenshot-of-webpage-370275.html"&gt;Screenshot of webpage&lt;/a&gt;" thread. It uses ImageMagick for image manipulation.&lt;/p&gt;

&lt;p&gt;From reading the &lt;span class="fix"&gt;Win32::CaptureIE&lt;/span&gt; POD, the CapturePage function does exactly what I want:&lt;/p&gt;

&lt;div class="quote_simple"&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;CapturePage ( )&lt;/strong&gt; Captures whole page currently loaded in the Internet Explorer window. Only the page content will be captured - no window, no scrollbars. If the page is smaller than the window only the occupied part of the window will be captured. If the page is longer (scrollbars are active) the function will capture the whole page step by step by scrolling the window content (in all directions) and will return a complete image of the page.&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;p&gt;After installing ImageMagick, &lt;span class="fix"&gt;Image::Magick&lt;/span&gt; and &lt;span class="fix"&gt;Win32::CaptureIE&lt;/span&gt; on my Windows / ActiveState Perl system, I generated &lt;a href="/images/articles/200607/dev411blog_win32captureie.png"&gt;this screen shot&lt;/a&gt; with the following short program using no additional processing:&lt;/p&gt;

&lt;pre&gt;#!perl
use strict; use warnings;
use Win32::CaptureIE;

StartIE( width =&gt; 900 );
Navigate( 'http://www.dev411.com/blog/' );

my $img = CapturePage();
$img-&gt;Write( 'capture.png' );
QuitIE;&lt;/pre&gt;

&lt;p&gt;Perl and CPAN continue to amaze me with their treasure trove of functionality. Are there  similar tools for using Firefox, Linux, other image libraries or languages?&lt;/p&gt;

&lt;div class="update"&gt;&lt;p&gt;&lt;b&gt;UPDATE:&lt;/b&gt; ishnid has found two programs with CLIs (posted to the same thread):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://khtml2png.sourceforge.net/"&gt;khtml2png&lt;/a&gt; on SourceForge. This is a command-line program that looks like it can be run without a browser. It uses &lt;span class="fix"&gt;libkhtml&lt;/span&gt; (used by Konqueror) and ImageMagick's &lt;span class="fix"&gt;convertn&lt;/span&gt;.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://pearlcrescent.com/products/pagesaver/"&gt;Pearl Crescent Page Saver&lt;/a&gt;, a commercial app but available in a free version. This is a Firefox extension and requires the browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;b&gt;UPDATE 2:&lt;/b&gt;: I recently tried Win32::CaptureIE with ImageMagick 6.3.0 and it doesn't work. Apparently there used to be a link to "PerlMagick" in older versions of ImageMagick that may not exist anymore. Unfortunately Win32::CaptureIE relies on PerlMagick.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;UPDATE 3:&lt;/b&gt;: I just tried the free version of Pearl Crescent with Firefox 1.5.0.7 which it says it should support but I get a "Download error" with pageserverbasic-1.3.xpi.&lt;/p&gt;

&lt;/div&gt;</content>
  </entry>
  <entry>
    <author>
      <name>John Wang</name>
    </author>
    <id>urn:uuid:5bd12f134d64f49b67f22215e9476f5f</id>
    <published>2006-06-01T15:14:00-05:00</published>
    <updated>2007-06-16T12:30:22-05:00</updated>
    <title type="html">Prototype - X-JSON fails on long value in IE</title>
    <link href="http://www.dev411.com/blog/2006/06/01/prototype-x-json-fails-on-long-value-in-ie" rel="alternate" type="text/html"/>
    <category term="json" scheme="http://www.dev411.com/blog/tag/json" label="json"/>
    <category term="ie" scheme="http://www.dev411.com/blog/tag/ie" label="ie"/>
    <category term="ajax" scheme="http://www.dev411.com/blog/tag/ajax" label="ajax"/>
    <category term="prototype" scheme="http://www.dev411.com/blog/tag/prototype" label="prototype"/>
    <summary type="html">&lt;p&gt;Unlike Dojo Toolkit and other client-side AJAX libraries that read a JSON object from the response body, prototype.js reads it from the custom X-JSON header. I didn't run into any problems with prototype's approach developing on Firefox but I soon discovered IE 6 has a max header size that will cause prototype 1.5.0 rc0's evalJSON method to silently fail with an unreported [object Error] error. In my case, IE 6 would handle an X-JSON string with length of 138 bytes but would fail with a length of 1659 bytes. Firefox 1.5.0.3 and 1.0.7 worked fine with both strings. I'm not sure what IE 6's exact limit is but the fact there's a limit at all is discouraging IMO.&lt;/p&gt;

&lt;p&gt;The argument I've seen for putting the JSON object in X-JSON is that you can put a separate large quanity of HTML in the response body. This design works well when you only have one or zero large quantities of HTML. As soon as you have two, you need to either put them both in the response body using another serialized data notation or put them both in the JSON object and put the JSON object in the response body instead of the X-JSON header. It seems better to simply expect the JSON object in the response body in all cases than in cases when there's only one or zero large return values.&lt;/p&gt;

&lt;p&gt;Let's take a look at an example. In the following the one Ajax JSON response can return meta data about the overall response ("Result":"ok") as well as a list of "Posts", say when updating a post list on something like Digg's homepage. Further more a list of "Hot Stories" can simultaneously updated in the same request. Each one of the stories may have a description or overall information that exceeds IE 6's max header length.&lt;/p&gt;

&lt;pre&gt;{
  "Result":"ok",
  "Posts":[
    {
      "time":1149349580,
      "id":100001,
      "title":"Article 11 title",
      "desc":"Article 11 desc
         (longer than IE header length)",
      "votes":120,
      "comments":5,
      "submitter":"garfield"
    },
    {
      "time":1149349583,
      "id":100002,
      "title":"Article 12 title",
      "desc":"Article 12 desc
         (longer than IE header length)",
      "votes":125,
      "comments":15,
      "submitter":"garfield"
    }
  ],
  "Hot Stories":[
    {
      "time":1149348000,
      "id":1001,
      "title":"Hot Article 1 title",
      "desc":"Hot Article 1 desc
         (longer than IE header length)",
      "votes":1120,
      "comments":115,
      "submitter":"garfield"
    },
    {
      "time":1149349000,
      "id":1002,
      "title":"Hot Article 2 title",
      "desc":"Hot Article 1 desc
         (longer than IE header length)",
      "votes":1120,
      "comments":115,
      "submitter":"garfield"
    }
  ]
}&lt;/pre&gt;

&lt;p&gt;I understand where having a proprietary X-JSON header and a separate response body is useful however I view those situations as a subset of a more generic, and powerful, use. With more complex return values, putting the JSON object in the response body is ultimately a more flexible and extensible design.&lt;/p&gt;

&lt;p&gt;I'll continue to use prototype for now but I'm going to set all my JSON objects in the response body and eval it myself given IE 6's short comings. A bigger concern for me is that I feel Prototype's use of putting the JSON object in X-JSON will encourage inefficient AJAX implementations that end up using more HTTP request/response cycles than necessary. I really hope prototype.js will move their auto-eval feature to operate on the response body due to this problem and to make it more compatible with other JS AJAX libraries at the same time.&lt;/p&gt;</summary>
    <content type="html">&lt;p&gt;Unlike Dojo Toolkit and other client-side AJAX libraries that read a JSON object from the response body, prototype.js reads it from the custom X-JSON header. I didn't run into any problems with prototype's approach developing on Firefox but I soon discovered IE 6 has a max header size that will cause prototype 1.5.0 rc0's evalJSON method to silently fail with an unreported [object Error] error. In my case, IE 6 would handle an X-JSON string with length of 138 bytes but would fail with a length of 1659 bytes. Firefox 1.5.0.3 and 1.0.7 worked fine with both strings. I'm not sure what IE 6's exact limit is but the fact there's a limit at all is discouraging IMO.&lt;/p&gt;

&lt;p&gt;The argument I've seen for putting the JSON object in X-JSON is that you can put a separate large quanity of HTML in the response body. This design works well when you only have one or zero large quantities of HTML. As soon as you have two, you need to either put them both in the response body using another serialized data notation or put them both in the JSON object and put the JSON object in the response body instead of the X-JSON header. It seems better to simply expect the JSON object in the response body in all cases than in cases when there's only one or zero large return values.&lt;/p&gt;

&lt;p&gt;Let's take a look at an example. In the following the one Ajax JSON response can return meta data about the overall response ("Result":"ok") as well as a list of "Posts", say when updating a post list on something like Digg's homepage. Further more a list of "Hot Stories" can simultaneously updated in the same request. Each one of the stories may have a description or overall information that exceeds IE 6's max header length.&lt;/p&gt;

&lt;pre&gt;{
  "Result":"ok",
  "Posts":[
    {
      "time":1149349580,
      "id":100001,
      "title":"Article 11 title",
      "desc":"Article 11 desc
         (longer than IE header length)",
      "votes":120,
      "comments":5,
      "submitter":"garfield"
    },
    {
      "time":1149349583,
      "id":100002,
      "title":"Article 12 title",
      "desc":"Article 12 desc
         (longer than IE header length)",
      "votes":125,
      "comments":15,
      "submitter":"garfield"
    }
  ],
  "Hot Stories":[
    {
      "time":1149348000,
      "id":1001,
      "title":"Hot Article 1 title",
      "desc":"Hot Article 1 desc
         (longer than IE header length)",
      "votes":1120,
      "comments":115,
      "submitter":"garfield"
    },
    {
      "time":1149349000,
      "id":1002,
      "title":"Hot Article 2 title",
      "desc":"Hot Article 1 desc
         (longer than IE header length)",
      "votes":1120,
      "comments":115,
      "submitter":"garfield"
    }
  ]
}&lt;/pre&gt;

&lt;p&gt;I understand where having a proprietary X-JSON header and a separate response body is useful however I view those situations as a subset of a more generic, and powerful, use. With more complex return values, putting the JSON object in the response body is ultimately a more flexible and extensible design.&lt;/p&gt;

&lt;p&gt;I'll continue to use prototype for now but I'm going to set all my JSON objects in the response body and eval it myself given IE 6's short comings. A bigger concern for me is that I feel Prototype's use of putting the JSON object in X-JSON will encourage inefficient AJAX implementations that end up using more HTTP request/response cycles than necessary. I really hope prototype.js will move their auto-eval feature to operate on the response body due to this problem and to make it more compatible with other JS AJAX libraries at the same time.&lt;/p&gt;

</content>
  </entry>
</feed>

