Difference form submission in Javascript

This article will introduce a the concept of “delta differencing” form submission in Javascript and discuss the benefits of using this concept.

As yet I have been unable to find any open source libraries and have not heard of any projects that use this concept other than those that I have worked on. I would be very interested to hear of any projects that do already have a working implementation.

What is delta differencing
Delta differencing is a method of performing data backup that only stores the changes in data since the last backup. For a more detailed explanation of delta difference backups see this page. The idea behind this method (for backups at least) is that it will reduce the amount of storage required for the backup to be performed.

So now that we know what delta differencing is and how is used for backups we can apply this same concept to web forms.

delta differencing in web forms
In a web form the delta differencing concept is applied by disabling form fields using Javascript before the form is submitted if they have not changed since the page/form was loaded. This will mean that only the values for the fields that have changed are submitted to the server effectively creating a “diff” of the form data.

To checking whether a field has changed in most cases should be done using the defaultValue, defaultChecked and defaultSelected properties in Javascript. These properties maintain the original value of the field once it has been changed by the user so by comparing this property and the current value of the field you will be able to tell if the field has changed.

There are some cases that need special consideration when disabling fields such as check boxes and radio buttons. Also, the concept should not be applied to hidden fields as these fields are not directly changed by users.

What’s it good for?
The main advantages that using delta differencing for form submission offers are:

  1. Smaller request sizes when submitting forms – less network traffic. Particularly good for large, complex forms
  2. Prevents users from “clobbering” other changes in cases where multiple users are editing the same “record”

This concept is mainly useful for web applications with high numbers of users and/or high volumes of traffic. I would not typically recommend using this for a general websites where users are not editing existing records as the Javascript does add extra overhead to the form submission.

New records in an application
In a web application when you are creating a new record it would be highly unlikely that you want any of the fields to disable. For this reason I would suggest not adding the Javascript to your form in the case of new records.

Groups of fields
In some forms certain fields may be related to other fields. As a result of this relationship you may want all related fields to be submitted regardless of whether they have changed or not. In this case there is a couple of options:

  1. Disable the delta differencing altogether
  2. Add support for “groups” of fields in your Javascript. If any of the fields in a group change, all fields will be submitted

Final Thoughts
I have several working implementations of this in various applications. I am currently working on a stand alone Javascript library that will be provided in our projects section once completed.

If you want any further information or need input when writing your own implementation please feel free to contact me. Additionally, I would love to hear your thoughts on the delta differencing concept and this article in general so please leave comments.

That’s all for now.

  • I am not an ASP.NET developer so please correct me if I am wrong but my understanding of view state is that it is intended to maintain (persist) state across multiple posts. It does this by adding a hidden field to the page that carries around ALL of the data potentially making the requests quite large.

    The main purpose of the concept I am proposing is to reduce the number of fields being posted back to the server (either for performance or to allow multiple users to edit the same record concurrently). Another major difference is that this concept is purely Javascript. It doesn't require anything to be done on the server side other than for you application to be aware that not all fields will always be posted.

    Hope that helps to clear things up.
  • This kinda sounds like ASP.NET's ViewState mechanism
  • Hi!

    I've been using difference form submission through custom Javascript as I'm not aware of any library that does this. I usually have to rebuild the script for each project due to intellectual property issues :-(

    -Nitin
  • We haven't done any benchmarking to measure performance. Any performance increase or request size reduction would no doubt be minimal unless you are dealing with quite large forms. The main reason we have used it was to avoid "clobbering" of data in high user applications.

    I have developed an application that uses this concept in AJAX. It does perform the form submission slightly differently to typical forms and so does not need to disable the fields themselves. It would also be possible to disable and re-enable the fields.

    I will be posting an example library for this concept soon and I will also investigate the possibility of writing a jQuery plugin.

    Thanks for your comments.
  • That's interesting indeed. Do you have any numbers showing how much it helps? Also, do you use it with xmlhttprequest queries? Because if you leave the form available for more input you'd need to reenable the correct fields too.

    A jQuery plugin would be great, especially one that could work side by side with the form plugin.
  • Jann
    good idea to use default values. Didn't know they exists. :o
blog comments powered by Disqus