Skip to content

Commit 062f6cd

Browse files
committed
spa splash page optimization article - rough draft
1 parent 9b2ad74 commit 062f6cd

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
layout: post
3+
title: Optimizing Single Page App Splash Screen
4+
author: fernando
5+
---
6+
7+
With this growing trend of making your website/app all fit in on single
8+
page, initial page load tend to take a bit longer. The advantage being that
9+
after only small bits of JSON will be passed to/from the client/server.
10+
11+
When I started working on Jackpine website, I put little attention on the images
12+
that where being handed over from the graphic designer. And pretty soon the total
13+
size for the page download was nearing (insert estimated webpage size)
14+
15+
I though maybe we should first focus on what the user see when they first hit the page.
16+
The background image of the chisel where the one that at around XXmb would load at the
17+
end of the stack and would slowly reveal itself. This looked horrible. So after some
18+
searching on the web on how to priotize the GET request for the background image I found
19+
that by default background images are last to build becasue they are set in the CSS.
20+
You could inline the css background but that would make the HTML structure have styling not
21+
cool for the semantics nerds. And even if you did add the inline it would still load after
22+
GETting all those huge JS libraries needed.
23+
24+
The solution I found that works the best is to instantiate a Javascript image object with
25+
the source of the image.
26+
27+
CODE HERE
28+
29+
img = new Image;
30+
img.src = 'image/source.png'
31+
32+
And placing this inline at the top of the html page before any calls to the JS or CSS, GETs
33+
image before anything else. For more bonus points in quick loading don't use any jQuery, just
34+
straight JS and it will shave a few milliseconds. And for even more make a low res picture and
35+
overlap the images using the CSS background comma spearated.
36+
37+
background-image: url(low-res.png), url(high-res.png);
38+
39+
This will basically load the first image on the list and once the next image is complete it will
40+
overlap it in a sudden blink. The effect is pretty suddle if you aren't looking for it.
41+
42+
Now your page might be getting somewhere and looking a little more snappy on the first laod.
43+
To really polish it off add and fade in effect to the text and your page is on its way to really
44+
pro work. Because what happend is that if you are using some fancy web font this again add to a
45+
bit of timing that cause the text to rended with some default font followed by the web font.
46+
And since the image is the screen first you might want the fade in in to avoid having a nasty
47+
flash of text.
48+
49+
Well all this shouldn't add to much time to your project for adding some extra quality to your
50+
site. Feel free to check the source code on this site. And I hope you enjoyed this tech write up.
51+

0 commit comments

Comments
 (0)