Archive for the 'javascript' Category

Faster JavaScript with jQuery

Sunday, August 5th, 2007
Recommended
Reading

book
book

As you start to build more AJAX features into your application you will be writing more and more JavaScript. Even though we are getting more tool support for JavaScript, especially with Visual Studio 2008, it can still be difficult to work with JavaScript because of browser differences. Even changes between Internet Explorer 6 and 7 can be troublesome. To minimize these problems I have been leveraging different JavaScript libraries which provide a rich set of features that have already handled the cross-browser issues. My favorite has become jQuery for multiple reasons.

The main reason I like jQuery is the fact that it is designed to do more with less code. The programming model lends itself to very compact code that does a lot for you. It also has a rich querying model that allows you to use CSS selectors to find elements within a web page and apply various changes on those elements. And another great reason to use it is the fact that it allows you to write much faster JavaScript. The jQuery model allows you to chain methods together. Each call to jQuery starts with a query like $('div.content') that will match all div blocks in the with content set as the class name. The method returns a jQuery object which can then be used to call another method, like addClass('Highlight') that will add Highlight as a class name to all of the matched elements. It will then return the jQuery object again for another method to run a jQuery method. Chaining the calls allows the same objects to be used over and over so you can avoid the overhead of creating objects which is expensive.

(more...)

Using Overflow for Inline Frames

Saturday, July 14th, 2007

I have always wanted to know how some of the fancy layouts that Google uses actually work. The mail and reader applications both have sections within the page which I always assumed where just inline frames with the iframe tag which I personally avoid. But I recently discovered that you can achieve the same affect using div tags with the CSS value for overflow set to auto or scroll while the height is also set.

(more...)

Vote for Full Intellisense Support of Javascript

Wednesday, June 20th, 2007

Visual Studio 2008 already includes some basic support for Intellisense in Javascript. It is actually quite amazing what you can do with it but it apparently does not fully support Javascript source files that are embedded within an assembly. I use this technique with my SmallSharpTools.EmbeddedScripts project. You can see it in action with some of the demos I prepared. It includes a smart server control that manages the script dependencies with helpful design-time support. What would be extremely useful would be a way to have Visual Studio 2008 pick up the script references like normally referenced scripts.

If you agree, and I hope you do, please vote on the feedback item I opened.

(more...)

Is the iPhone Warming to Silverlight and JavaFX?

Saturday, May 12th, 2007

I seems that Apple has cracked open the door for third party applications on the iPhone. I hope this means that at least third party XHTML/AJAX applications will be possible. Many of the the mini applications (widgets, dashboard, gadgets) which have become popular over the past year are basically just mini web applications. They render their layout and graphics with standard XHTML, CSS and images with their behavior provided by an enhanced superset of Javascript.

While it may seem limited to networked applications, it will soon be possible to create web applications which work offline with local storage just like a "real" application. Such an application could locally store your preferences such as your zip code and weather data so that when you look at the weather forecast it does not always have to connect to the internet. Since the AJAX explosion there have been a greatly increasing number of tools to support development with Javascript so it is becoming easier every day to build these kind of applications.

But we can now consider using Java and .NET for these mobile applications which could eventually include the iPhone. It seems inevitable anyway. I think it is no accident that Silverlight was ported to work on MacOS X with a very small footprint. They clearly want to make it possible to deploy Silverlight applications to mobile platforms as well, and since the iPhone is running an OS which Apple claims is pretty much the same as MacOS X it may be trivial to extend Silverlight to the iPhone.

(more...)

The Near Future of ASP.NET

Saturday, May 5th, 2007

It won't be long before we can get our hands on the final release of Visual Studio "Orcas" and .NET 3.5. For those of us who did not attend MIX '07 you can still get a sneak peak. I watched Web Development Using Visual Studio "Orcas" by Omar Khan and I am quite impressed with the changes they are going to include.

(more...)

Packer 3.0 for .NET

Monday, April 30th, 2007

I recently fixed a bug in a widely used Javascript library and once I was done I needed to shrink the library to get it back to the previously reasonable size. To do so I planned to use Packer by Dean Edwards, a popular tool which uses a clever technique to eliminate duplicate strings in a library. Many times you will get some very good compression ratios. When a Javascript library grows beyond 100k it is helpful to make use a tool like Packer.

When I looked at using Packer I found a previous version for .NET which offered part of what I needed with a limitation due to the WinForm interface. I reused the classes which did all of the work with a newly created console application which took multiple filenames to compress all of the files into a single output which is commonly done with Packer. Once I added this functionality I packaged it with an installer and published it on SmallSharpTools.com.

This console application should come in handle in certain scenarios, such as a post build deployment. I have a few ideas for future releases once I have more time. Those ideas at listed on the project page.

Web Development Tools for the Power Developer (Revised)

Monday, April 2nd, 2007

Six months ago I wrote Web Development Tools for the Power Developer which covered the progress that has been made with tools for web development. It got picked up by a few popular websites and through the various comments I learned about a few additional tools I did not know about previously. The two most useful bits that I found were Firebug and jQuery.

You can see the power of Firebug and jQuery in a demo by John Resig which I have leveraged heavily since I have seen the video. I used his example to pick apart some effects used by the ASP.NET AJAX Toolkit as shown in my own video. And now my newest website, LinkMindr.com, is using jQuery as the main engine for the key functionality. Look at the source and you will be surprised that the Javascript running the website is under 40 lines of my own hand written Javascript especially for what it does.

(more...)

How Big is Your Javascript Library?

Sunday, February 25th, 2007

One of those hallway debates that keeps coming up lately is over the size of the popular Javascript libraries. The single most popular library is Prototype which comes in at a whopping 70KB. That large size has some developers screaming bloody murder because they think that it actually requires you to download 70KB of data, and it does, unless you take advantage of HTTP compression which is supported by IIS 6 and the Apache web server.

(more...)

How Big is Your ViewState?

Wednesday, February 21st, 2007

One way to speed up an ASP.NET application is to trim ViewState as much as possible. You can do it by turning off ViewState for controls which do not need it or to move the ViewState to the server-side by adjusting the Page State Persister. To keep an eye on your ViewState you can use the following link as a bookmarklet which will tell you the length of the ViewState for the current page.

ViewState Length [save this bookmark]

(more...)

GPlotter 0.90 Released!

Tuesday, February 6th, 2007

I have updated GPlotter to make use of the revised Google Maps API. I also completely restructured the Javascript to a much more object oriented coding style. I am using the latest release of Prototype, which recently moved to a new location as well as posted a great deal of new documentation. I am using Prototype for the object inheritance and AJAX functionality.

GPlotter still works as it did before but Google did change the zoom level. You will want to change the zoom level in your XML files. (see Zoom Level Order) The documentation explains the new zoom should be 17 minus the old zoom value.

Perhaps best of all, to change GPlotter for your own custom purposes you can use the Prototype inheritance mechanism to inherit and extend GPlotter. And if you do extend or customize GPlotter I would like to see your changes. I would be happy to consider incorporating your changes into GPlotter if the new features are helpful to others.

(more...)