Creative Jar Blog RSS Feed

Dynamically adjusting height of IFRAME from child page

October 20, 2008 11:20 by nat

I had to do this recently and thought it would be tougher than it ended up being. Here's the code I used:

function adjustMyFrameHeight()
{
var frame = getElement("myFrame");
frame.height = document.body.offsetHeight + 60 + "px"; // add 60 pixels to be safe...
}

function getElement(aID)
{
return (document.getElementById) ?
     parent.document.getElementById(aID) : parent.document.all[aID];
}

Then, just simply call the "adjustMyFrameHeight()" method from the child page's BODY onload event:

<body onload="adjustMyFrameHeight();">

Et voila, c'est bon!!


Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Improving .NET Website Perfomance

October 17, 2008 09:18 by nat

A couple of the CJ Dev team were down in Brighton for Re-Mix 2008 a few weeks ago, and one of the most useful sessions I went to was "ASP.NET Front End Performance" by Chris Hay.

There's some really obvious things, but others that I didn't know. I've collated the key points together for easy reference:

  • Combine all JavaScript files together (i.e. single request)
  • Combine all CSS files together (i.e. single request)
  • Use inline scripts and CSS on the home page, load script and CSS assets post UI
  • Reduce image requests
    • Use image maps
    • Use large background images
  • Implement IIS caching
  • Use versioning policy on filenames to avoid unwanted caching (e.g. my-js-file-001.js)
  • Use Server.Transfer instead of Response.Redirect where possible
  • Use SilverLight controls for common areas of the site (headers, footers, etc.)
  • Implement HTTP compression in IIS
  • Use the .NET ViewState wisely
    • Only on pages where necessary
    • Compress the ViewState
    • Offload ViewState to Session if possible / advantageous
  • Avoid use of .NET UpdatePanel control where possible
  • Expose web services to AJAX for use by JavaScript code, manually altering DOM
  • Combine auto generated scripts by .NET framework (e.g. ScriptResource.axd)
    • Use script resource profiler to discover all script files
  • Use SilverLight instead of AJAX
    • Detect presence of SilverLight, and fail safe to AJAX if preferred to forcing use of SilverLight
  • Use Content Delivery Network where applicable (large projects) to bring the content closer to the user
  • Implement use of data caching
  • Use page / control output caching  
  • Queue requests for processing (if any large / long requests will occur)
  • Ensure all debug flags are removed from application

Cheers to Chris Hay!!


Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Regular Expressions - Everyday use with System.Text.RegularExpressions.Regex.Replace()

April 10, 2008 09:28 by nat

I recently had to display some text on a page where the source field was fully marked up html, but I only wanted the content. I imagined a long drawn out process of doing a string.Replace() on all html tags, and was considering booking a holiday, when REGEX came to the rescue. It was so simple - much simpler than I ever thought it would be.

Using the expression "<.*?>" to match all html tags, i then called the System.Text.RegularExpressions.Regex.Replace() method, which is very similar to string.Replace, only you can pass a regular expression to replace only the matches, and voila - all the html markup is removed.

Simple now that I think of it, but before I had seen this used, this task seemed a real pain in the behind.

A couple of useful regex resources:
http://www.quanetic.com/regex.php - on online REGEX testing tool
http://www.regular-expressions.info/reference.html - REGEX reference site - from basic to complex, everything you need.

Hope this comes in handy...

Nat


Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Calendar

January 2009
SuMoTuWeThFrSa
28293031123
45678910
11121314151617
18192021222324
25262728293031
1234567