Remove Initial Flicker With Smooth Gallery

I recently created a site (in beta testing now) with Smooth Gallery and the client loved it.

The Problem:
The only issue was that upon the initial page load – all items in the gallery would flicker for a second or two while the first image loaded – causing this to not look professional at all.

The Solution:

  1. HTML: I took the example code:
    <div>
    
      <div class="imageElement" id="element">
          <h3>Item 1 Title</h3>
          <p>Item 1 Description</p>
          <a href="#" title="open image" class="open"></a>
          <img src="images/brugges2006/1.jpg" class="full" />
          <img src="images/brugges2006/1-mini.jpg" class="thumbnail" />
       </div>
     
     </div>
    

    I then added an ID to each div (id=”element1″) so that each div had a class of “imageElement” and a unique ID (element1, element2, etc).

  2. CSS: Now that I had IDs to style, I added the following to my style sheet:
    #element2 {display: none;}
    

By adding the 2 bits of code mentioned below, I was able to initially hide the content in the second div so that only the content in the first div appeared on page load. Once the script started running, it then changed the display from none to block automatically. Problem solved.

Site Optimization

I have been busy the past three months working on a site optimization project for a startup company where the code had been written by 10+ programmers who had come and gone over the last year. That left a big site with lots of unused and crazy CSS, images, javascript, and nasty HTML structure. I approached this project with two stages in mind:

  1. Start clean with CSS and XHTML. The first thing I did was unlink the main 5 thousand line CSS file along with a handful of others which was wreaking all kinds of havoc. I then went into every view, standardized the overall HTML structure (so it could hold it’s own without any CSS), and then only added in the CSS that was used.
  2. Maximize HTTP requests. The next phase will involve spriting images and pairing down and combining javascript so the number of HTTP requests goes way down.

The initial results:
Total HTTP Requests: 192
Total Size: 1353141 bytes

After the first stage (finished today), the general results:
Total HTTP Requests: 67
Total Size: 693064 bytes

After stage two is completed – I think I can get those numbers down by another half.

From Yahoo!:
“80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.”

Why does all this matter? Think of a big, busy site. Think about the number of users – and then multiply that by the number of requests as well as the size of each page load. If you want good performance from your site – the pay off from optimizing your site will really pay off. It is pretty easy to go through your site and cleanup small things that over time will really add up. Not using a javascript you once did? Remove it from the header. Redid the site but still have a link to the old CSS “just in case”? Get rid of it! Remember, a little goes a long way.

Terms of Use Javascript

Need: A script that a client could easily call within a URL to force the users to agree to their terms of use before downloading a file.

Solution:Either put the following code in the header, or in a .js file to include:


function terms(){
	question = confirm("Terms of Use text here")
 if (question !="0"){
		document.URL()
	}
  }

Then, call this code in your HTML code by using:

<a href="http://www.sandboxdev.com" />Download Link</a>