Compsoft Flexible Specialists

Compsoft plc

Compsoft Weblog Compsoft Website News Archive Privacy Policy Contact Us  

Thursday, October 15, 2009

CDNs (CD what nows?)

With the ever increasing demands that come with scale on popular websites, site owners are always looking for ways to move resource demands away from their traffic inundated servers.

There are a number of ways of offsetting or distributing demand, I'm going to cover just one, Content Delivery Networks (CDNs).

Content Delivery Networks are servers which host duplicate copies of a given resource or resources, this might be your site's images, javascript or media.

Why might you need to move your resources to a CDN?

When your browser downloads a web page, it has a limited number of active connections it can make to a domain, typically around 2.

This means that if it's busy downloading images on one, and media on another, you're not going to see the page until both have finished downloading.

Pushing those resources to other domains via a CDN means you get:

  1. More active connections available so the page can load quicker.
  2. Resources can be pulled down from locations geographically closer to the user, resulting in even faster page speeds.
  3. A reduced load on your server, no bandwidth cost on your server.
  4. Duplication of your resources gives you redundancy failovers if servers are down.
  5. Sites that use the same resources, which a user has previously downloaded, will not need to download them again, giving big speed gains.

You can see how there are some immediate benefits to using them.

Want to use one now?

Google and Microsoft have somewhat closed CDNs meaning they won't host your content, but they do host some common files you might need, such as jQuery.

   1: <script src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

Or:

   1: <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>

So why wouldn't you use them?

Cost, there are a whole lot of ways you can customise your requirements, number of servers, redundancy, global availability etc. Akamai, Amazon, CacheFly and Limelight Networks all have offerings in this space.

Having issues with scale or need a high demand, high availability site and need help? contact Compsoft today.

Tuesday, October 06, 2009

Mail merging with PDF documents

We tend to find that mail merge with word documents is a flexible mechanism for customers to control the output of their applications. Be that invoices, emails or reports. Using simple merge merge documents allows the customers to modify the output of the system without having to contact us. We find that the word mail merge solution provided by ASPOSE Words is simple and reliable.

We recently had a customer that required pre made PDF forms to be source of the outputs from their system. After a quick search of the ASPOSE solutions, we found that the ASPOSE PDF Kit had exactly what we needed.

10 lines of code later, we could as easily mail merge against PDF documents as we could against word documents.

MemoryStream outputStream = new MemoryStream();
MemoryStream pdfForm = new MemoryStream(this.Binary.Data);
Form form = new Form(pdfForm, outputStream);

foreach (string fieldName in form.FieldsNames)
{
object fieldValue = "";
if (mailMergeDataSource.GetValue(fieldName, out fieldValue))
form.FillField(fieldName, fieldValue.ToString());
}

form.FlattenAllFields();
form.Save();

return outputStream;



Thank you ASPOSE!

Monday, October 05, 2009

This week, I have been mostly getting JSONP

I've just finished writing a test harness for a sms texting service. While writing this little tool I ran into a problem with cross site scripting issues.

Essentially its a form that is submitted to a page which then invokes methods to deal with the faked sms. It actually plays the part of the sms gateway host and saves me 50pence a shot!

The form submission is via AJAX, but because its on a different domain I get no success or useful error responses. This is where JSONP comes in.

As of jQuery 1.2 you can get JSON data from another domain if you add a JSONP callback and a little bit of handling on the server.

You also get the proper success and error responses.

The form looks a little like this:

<form action="http://someOtherDomain/cross-site.php" method="get">
 input1:<input id="input1" name="input1" value="suits you sir"/>
</form>
<button type="button" id="btnsubmitjson">jsonp submit</button>
<div id="response"></div>


The javascript that handles the button click event appends the JSON callback to the url and then submits the form with the power of jQuery:

function submitjson(){
    posturl = $("form").attr('action');
    posturl += "?jsoncallback=?"; //append the JSON call back
    $.getJSON(posturl, $("form").serialize(), function(data) {
        $('#response').text(data.name);
    });
}

And the final part (which is not so obvious) is the response required, generated by the server:

<?php
$data = '{"name" : "'.$_GET['input1'].'"}';
echo $_GET['jsoncallback'].'('.$data.');';
?>

And its this last magic bit in the responding with $_GET['jsoncallback'] which makes it all work!

Now I can point my tool where ever I like, AND get the right responses (ah yeah).

Labels: , , ,