Whimsical.nu

Welcome to “Geek chick”

I've been making websites as a hobby since 1998, and I do it for a living. There's down-to-earth, from-me-to-you bits and pieces of the art of web-hobbying as well as other geeky thoughts.

Implementation focus: quick spoiler hiding

I'm talking about: W.nu's hide spoiler JavaScript

I’d like to share a very nifty, quick-to-whip-up piece of code I use for the book reviews I will be doing from here on out, in my Reader category: a short JavaScript snippet to hide spoilers (you can see it in action in my Mockingjay review). You see, I suck at making book reviews: I always inevitably talk about things that is best left to be discovered by a reader. So to help myself and anyone who might chance upon my reviews, a spoiler protection feature for my blog sounds just about right.

Why I didn’t go with the “More” tag route

WordPress has a feature that lets you force users to click through to the post’s dedicated page: essentially, hiding anything under the “More” tag when viewing in the blog index/posts list.

Insert More tag WP button

This works as a quick solution: but this didn’t really feel very “bright” to me. That’s an extra click and page load, and it means that I can’t have multiple spoilery sections in a single post. I don’t exactly know why I will need multiple separate spoilery sections, but far be it from me to set limitations on my writing style!

My solution

I went and used JavaScript to hide spoilers in the page. I did so for a couple reasons:

  1. Users won’t need to wait before seeing the hidden content: one click to surface it, and it’s there already.
  2. There is minimal break in the experience and tone of the entry.
  3. I could have as many spoilery sections in my entry, but the entry will still read as expected: you could just skip the spoilery sections easily.
  4. Users get the same experience whether they’re reading the entry on its own page or on the blog index page: spoilers will still be marked.
  5. Presentational text (show/hide spoilers) is not included in the content of the post.

The implementation

My library of choice is YUI3, but the same should also be relatively easy to do in other libraries, or even just plain JavaScript.

The script basically retrieves any and all tags with a class name of “spoiler” and hides everything inside that by lowering the opacity to 10%. This way, the user has a tantalizing, indistinct view of just how much they’re missing out by not reading the book/watching the movie! ;)

The script also adds its own text to the entry via JavaScript, saying that there are spoilers ahead and they can click on the text to toggle visibility. It’s not an actual link, but I wanted to style it slightly like a link–but you really have full freedom as to how you’d like the spoiler toggle warning to look like.

(As always, the best place to put the code below would be at the end of your page.)

<script type="text/javascript" src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"></script>
<script language="javascript">
YUI().use( "anim", function(Y){
    Y.all('.spoiler').each(function(o, i){
        var id = 'spoiler-' + i;
        var spoilerToggle = '<div id="spoiler-toggle-'+i+'" class="spoiler-toggle">Warning! Spoilers ahead! Click here to toggle spoiler visibility.</div>';
        Y.on( 'click', function(e){
            var opacityValue = ( o.getStyle('opacity') >= 0.9 ) ? 0.1 : 1;
            var anim = new Y.Anim({
                node: o,
                duration: 0.25,
                to : { opacity: opacityValue }
            });
            anim.run();
        }, '#spoiler-toggle-'+i );
        o.insert( spoilerToggle, o );
        o.setStyle('margin','20px').setStyle('opacity','0.1').setStyle('padding','10px');
    });
});
</script>

Without any HTML tags with the class “spoiler”, the script will not run unnecessarily, so you’re pretty free to use it for any page or post type.

To add styles specific to the spoiler toggle, you can use:

.spoiler-toggle { /* style for whole warning */ }
.spoiler-toggle span { /* style for toggle "link" */ }

Customizing the code

You can use the above code for almost any other similar purpose. You can change the element it hides by changing “.spoiler” at this line:

Y.all('.spoiler').each(function(o, i){

making sure that what you put in is a valid CSS selector (i.e., #some-id .some-class element or similar). It will then apply fading in/out to the whole element.

You can also well as change the wording of your toggle, or completely change it out to a different element (an image, or what-have-you) by changing the HTML at:

var spoilerToggle = '<div id="spoiler-toggle-'+i+'" class="spoiler-toggle">Warning! Spoilers ahead! Click here to toggle spoiler visibility.</div>';

making sure that you leave the outermost div with its ID intact.

Hope it’s useful, or helps you think of other ways to improve your site. Website improvement never needs to be a full-blown affair: a couple low-hanging fruit, small details here and there, makes the work worthwhile. ♥

0 Comments

Foursquare is not an option

I'm talking about: Foursquare and location-based services

I lead a relatively “visible” online life. I tweet and I blog, and I’ve been active in various communities and places ever since I’ve been online. I know a good number of people online, consider one of my best friends someone I met online, and a lot more people know of me through the Internet though I might not know them.

But Foursquare (and other location-sharing services) has never been an option for me. I realize you can limit visibility of your updates, but why will I want the world to know exactly where I am? I can understand the glamor of it if I travel–hey, I’m in Paris, and now I’m in Rome, booyah!–but I lead a rather normal, boring life. I wake up in the morning and get to work, and after work I either go home or pass by a place or two before retiring. Occasionally things are exciting: I have a dinner party to go to, or a trip for business or vacation.

But do I really want someone to have the ability to walk up to me and say “Hi! You’re angelamaria, I know you through the so-and-so website! I saw you were here on Foursquare and thought I’d say hi!”

Antisocial? Maybe, but I think it comes with the realization I have a lot less privacy than I thought I had.

There is no such thing as privacy online

I know the very idea of leading a vibrant online life seems to say the opposite: there is no such thing as privacy. Once it’s on the Internet, it’s there forever. And having been here for a long time, I’ve become a lot more protective of my anonymity.

“But I thought you said you liked online visibility!”

I know, I’m in a bit of a pickle, aren’t I? It’s just another juggling game. These services online–a lot of them are free, of no monetary cost to use, but you do give them something in exchange for using their services: your privacy. Sometimes the trade is fair, and sometimes it’s not enough. It’s up to each individual to find out where that fine line is.

A friend recently said that it seems that as we get older, we get a little more conservative with sharing. That’s completely true for me:

  1. 2000 – 2003 (thereabouts) – I had an online journal hosted on my website, maintained by hand. No permissions “system”. There were sometimes “hidden” links.
  2. 2001 – Livejournal created.
  3. 2002 – 2009 – Livejournal generally public, with friends-locked entries. As the years went on, I had more and more friends locked entries, and made heavier use of group filters.
  4. 2009 – present – Livejournal completely locked to public and contains only friends-only entries.

As I got older, privacy online has become more and more of an issue. People knowing what you had for breakfast is harmless for me, but people I don’t know knowing where to go find me to harass me is another matter.

And that’s why you’ll never find me in Foursquare ;)

3 Comments

Whimsical.Nu redux

I'm talking about: the new look of Whimsical.nu

(Mic test, hello?)

I haven’t fallen off the face of the Earth. There’s too little of Singapore to fall off of it already ;) I’ve been journaling and twittering, but hardly ever blogging for the time being, and my falling-out-of-love with my older layout just made it worse. So, a new layout! I’ve experimented with 1.) customizing other people’s layouts and 2.) not bothering with customizing other people’s layouts, but somehow nothing ever sticks. Maybe pre-made themes and layouts is just really for my journal, eh?

That said, this layout has been around three months in the making! I have had two other layouts that I’ve tried to work with, but I haven’t gotten to coding it up when I got tired of them; let’s hope this one sticks for a good bit. It had better stick–this is probably one of the most involved themes I’ve done, on par with–probably exceeding–my last theme for Indiscripts.

So of course I will have to point out just what I loved about making this theme!

  1. Slide-out tray. That “+” you see on the upper-left? Yes, that slides out (okay, it widens out…I spent half a day trying to figure out how to make it slide out but then I couldn’t be bothered) to reveal site menu and a couple of things you’d usually see in a blog sidebar. Not a lot, because it’s all just noise and clutter. Some menu items also expand.
  2. Category menu. If you’re looking at the blog index, you won’t see anything, but browsing through a category or viewing a single post page will replace the category menu item on the left with a HUGE tab. *pets it*
  3. HTML5. I don’t fancy feeling like such a beginner all over again, that’s for sure. I’ve started to familiarize myself with some HTML5 tags, but I fear this might be a repeat of 1998: Angela bungling along putting weird tags in weird places.
  4. Whimsical.nu logo! It’s not very inspired, I know. I’m not a logo designer person. But I like it anyway.
  5. Comments form! Come on, I know you want to click it. I’ve never really changed out the WordPress comments form layout before (except for *drum rolls* that last layout in Indiscripts), but doing this was quite fun.
  6. Single post next/previous link toggle. My, that was a mouthful. Now, if you wanted to cycle through previous and next posts in the same category while looking at single post pages, you can click on the placement indicator in the paginator at the bottom of the post, and change the paginator to cycle through the category instead of the chronological next/previous post. This needs a bit more work: a way for the setting to be “sticky”, for example.
  7. Simpler category link. Now you can get to each major category by going to whimsical.nu/category-name instead of needing to use whimsical.nu/category/category-name. This makes it much easier to share my top category links without it needing to be within the context of the whole blog: whimsical.nu/gamer, for example, looks like a standalone link than whimsical.nu/category/gamer.
  8. Archives page! Now, I know it looks quite plain, but I ended up hacking my WordPress a bit for wp_get_archives to show headings for the monthly archive and the alphabetical archive. So it may not look like much, but it’s much shinier now!

In line with the revamp, I’ve gone through all older posts and pages and removed a number of them: script-only updates, “website revamp!” posts without any other content, and scripts documentation. Script-y things will stay at my scripts archive, which will soon get a little sprucing-up; it seems things are b0rked at the moment.

Let me know if you see anything amiss (IE issues may still be skulking around, but feel free to let me know!), or have questions/comments/weird trivia on the revamp ;)

7 Comments

Looking for motivation

Right, I need a new journal/blog like I need a third pair of eyes (…on second thought, a third pair of eyes probably isn’t a bad idea), and I’m not “switching” (my permanent account at LiveJournal is doing very well), but skimming through the Dreamwidth newsletter is somewhat inspiring, and it’s making me feel nostalgic.

Take this gem:

This week gave us 45 resolved bugs (mark and fu were rocking the review queue), which are described in this week’s code tour by sporky_rat.

So, I realize that not everyone will read that and think coding and resolving 45 bugs in a week is “fun” and “glamorous”. However, it reminds me of the days when I was working on Enthusiast and my other scripts, of working on my couple dozen websites. It was fulfilling and fun to set out to do something and have it done quickly.

Now, where to find the motivation to look at PHP, HTML, CSS and JavaScript after a day’s work on the same thing? Or even to go back to web design? That’s what I’d like to know.

6 Comments

New layout, and tinkering with WordPress categories

I’ve been working on and off on this new layout for a while, but today I’ve doubled down to get it all coded and running. Nothing was wrong with the older layout, of course, but I just felt it was a little cluttered, and I felt somewhat pressured to write longer posts just to fill up all that space in line with the contents on the sidebar. Ergh. I also wanted a more obvious division between different categories, but not so much that moving from one category to the next would be a jarring experience.

So I came up with this :D I am rather pleased with it, especially for the coding that’s gone behind it. The layout has a lot of specific handling depending on which category the currently-visible post is in:

  1. Cartoon head background and post “icon” obviously depend on the post’s category; click on each of the categories to see them all.
  2. Where possible, I use the category’s “color” to indicate categories, such as the footer background, and the most recent category posts on the top right of the header.
  3. The top right header obviously shows the most recent post from each category–except, of course, when you’re already viewing that post!
  4. Post title color will also mirror the category the post belongs to.
  5. The next and back links found at the post’s meta area will also mirror the type of posts you’re scrolling through. A brown arrow means you’re not in a category!
  6. The contents of the footer will also vary slightly depending on the “active” category.

To pull most of the styling changes off, I needed the category of the post on the page itself, as well as on various areas of the blog to get the proper information. This wasn’t a problem for category pages, but for all the rest? I ended up doing a small bit of hackery (note this will only work on pages that contain just one post), and crossing my fingers that my blog won’t break in future WP versions:

function get_current_top_category() {
	$CATEGORIES = array(
		3 => 'girl',
		4 => 'geek',
		5 => 'reader',
		6 => 'writer',
		7 => 'gamer'
	);
	$current_top_category = 0;

	global $post;
	$post_id = $post->ID;
	$categories = get_the_category( $post_id );
	foreach( $categories as $c ) {
		if( in_array( $c->slug, $CATEGORIES ) ) {
			$current_top_category = $c->cat_ID;
			break;
		}
	}
	return $current_top_category;
}

The function works well both with just getting the current category for content manipulation, as well as adding an extra class to the body tag, as mentioned in this post via the body_class function.

All that said, I still need to get a couple of things working. I haven’t checked on IE browsers yet (and I don’t have any more plans of checking IE6… *shakes fist at it*), and I need to optimize the PNGs I used; I also want comments to show on each page, even if it’s not the single post page; and a couple more meta stuff couldn’t hurt, probably! They will all need to be done at a later date, though; I’m bushed!

Let me know if you see anything glaringly wrong :D

2 Comments

Moving hosts and htaccess rewrite rules

I’ve been at this since waking up this morning! I’m currently paying for two hosts, my older reseller account and a newer Grid-Service account with Media Temple, where W.nu is hosted. I’ve been doing this for quite a couple of months now, mostly because I’d been a bit too lazy to actually move my sites over; and my, it’s quite a handful.

A chunk of the “trouble” is that Media Temple has a specific file structure and control panel and whatnot. Don’t get me wrong, it’s organized and I love it, but it makes transferring stuff over a little more difficult. Transferring Seasonal Plume was easy (what an understatement), but Aking Mahal is another matter; I’m still at it.

The biggest “problem point” is that AM.net has a lot of subdomains. That meant a lot of things: cluttering up my MT control panel with subdomains, more than half of which are just pointers to new sites or a note that the fanlisting is closed; and each subdomain has a different placement than my older host which meant just dumping a backup wasn’t going to work, too. It means uploading things manually. Err. For three of my shrines I have screencaps. Lots of files, images, jpegs. Ouch.

And since I don’t care about clutter, that also meant that I needed to automatically point a nonexistent subdomain to a particular file that says “closed” or some such. I am a dunce with htaccess, which meant I spent most of last night and a good part of this morning researching on how to do this. I was able to do it finally though! Huzzah!

I present to you an htaccess rewrite rule to redirect particular subdomains to a certain file on the main website (needs to have wildcard subdomains working):

### Rewrite rules for closed fanlistings
RewriteEngine On
RewriteBase /
RewriteCond $1 !^gone
RewriteCond %{HTTP_HOST} ^(some|list|of|closed|subdomains)\.aking-mahal\.net
RewriteRule ^(.*)$ http://aking-mahal.net/gone.html [L]

Squee! It can be a bit manual (needing to put subdomains that are closed in the list) but this looks good, at least for now. And I found it out all by myself, so I feel pretty proud. ^_^ I still need to read up a couple more for another project, but I’m pleased enough that I got this far.

I should have AM.net moved over completely by end of today, with a new cleaner filesystem, ready for a revamp (when I get around to it, that is). Indisguise is another matter, though :( The biggest things I will have to move is my homegrown downloads script/repository (which also means all AM.net downloads will be broken until I get it back up), as well as various sites there, likeĀ Indiscripts, my wallpaper archive (which is in dire need of a revamp too), my LJ toys mini-site, and various other odds and ends. It’s quite daunting, but needs to be done, both to free up some money per quarter but also because I’m not too pleased with my older host these days.

2 Comments

SEO = black magic?

Occult Owl by jrbrubaker (flickr.com/photos/subconscience)

Occult Owl by jrbrubaker (flickr.com/photos/subconscience)

So I’ve been looking and doing some reading on Search Engine Optimization for a little project lately; though I’ve been on the web for quite some time already I’ve never really looked into SEO specifics. I suppose you could say I’ve taken some facts for granted, based on my own understanding of markup et al.

I know the usual, like:

  • Proper meta tag values to reflect purpose/content of page
  • Semantic markup
  • Good, “readable” URLs
  • Make content available on-page as opposed to post-loaded stuff, text is better, etc.

But those are kind of a given, at least if you’re a good web professional; if so, you should care about all these (and more). However, somehow it feels like SEO is some kind of esoteric undertaking, with bat wings and widows’ tears to boot. Come to think of it, I realize that do have a bit of a prejudice with “SEO professionals”, as I feel that they’re charging people/entities exorbitant amounts of money for stuff that a good, ordinary web professional should be able to do. I’m quite certain though, that there has to be more than just these things–hence the aforementioned “exorbitant amounts of money”–but what? Or is that some jealously-guarded industry secret?

(I’m talking about legit ways to improve search engine rankings. Or do these “SEO professionals” charge aforementioned amounts of money because they can game search engine rankings? Oy vey.)

Plus I came across a bit of a poser, regarding SEO and blogs. Obviously on a page you highlight important content headers with an H1 tag. But for blog index pages–what would that be? I’ve seen blogs/news sites/etc that mark the first article (headline) with an H1, and the blog/site title with a lower heading tag. But naturally I’ve also seen stuff the other way around. It all just means different views of which needs to be highest in priority, but I’m just curious about what most people practice: is it blog title in H1 and entry titles in H2 (or lower), or the other way around?

This all feels like black magic. :-s

Edited to add: I would love to have been proven wrong, but just a couple of hours after posting this entry, I ended up with “spam comments” on this entry from SEO “sites” and “blogs”. It’s spam because when your comment so does not have any connection to what I talked about in my post (other than “agreeing” that “SEO is important” and some such…which I never actually said in my entry!) that is spam.

Ugh. “SEO professionals” my ass.

5 Comments

The state of hobby-coding

This is something I’ve talked about for quite a while already on my personal journal, but never really mentioned in public. Hence it’s probably no surprise to a number of you–or maybe even to all of you, as I’m sure it’s been obvious that development on Enthusiast, and pretty much all of my other linkware scripts, have stalled. Being rather out of the loop recently with anything fanlisting-related, I actually have no idea if anyone’s still interested ;) but I would like to explain a little about what happened behind the scenes.

I enjoy coding. I enjoyed it many years ago when I made my first website from scratch, and I continue to enjoy it today. I especially enjoy making things that I can use but make it so that other people can use it, too. I like finding out that something I made is useful for others. That’s the whole reasoning behind all of the linkware scripts that I have done.

And then, Enthusiast happened. For whoever of you who have no interest in the fanlisting online community, you probably have no idea what it is. Enthusiast is a fanlistings and fanlistings collective management script, and a pretty damn good one (at the very least, back when I was active in the community). I have no idea where fanlisting scripts stand nowadays, but I’d like to think Enth is holding its own even if it’s old and “clunky”. I started writing the earliest versions for myself, prettied it enough to make it downloadable, and in no time at all it was huge (figuratively and literally).

It’s still my baby. I loff it the same way I loffed it before. But after months (a year? more?) of hemming and hawing, I’ve decided that I needed to step back from it, maybe temporarily, maybe permanently. Enth has affected my life a huge deal, in many different ways.

The good things:

  1. The no-brainer: easier fanlistings management! I love fanlistings, they’re cozy and cuddly. But they can be crazy in droves! But Enth has really pulled through for me on this.
  2. I learned a lot about PHP coding from making Enthusiast. A lot, from things I researched myself, and things people taught and showed me.
  3. I’ve met a lot of people via Enth; from users to fellow coders. A number of them I’ve grown quite close to, even if we’ve all slowly moved away from fanlistings.
  4. I can’t begin to imagine how much time I’ve spent on Enthusiast, but the time spent with it has been, on the whole, very enjoyable.

Enth’s popularity does have its downsides, such as:

  1. Enth’s slowly morphed into something almost unmanageable. I’ve felt a bit of pressure with doing this and doing that simply because, well, it’s what users want. While generally these are things that I do want somewhere down the line, it’s just slowly gotten to the point when my hobby project has become a bit of a burden and yet there’s this pressure to work on this, to fix this, to add this feature.
  2. The pressure related to this has affected my participation in the fanlistings community. I’ve felt guilty working on my fanlistings when Enth (Enth4 specifically) is still not done. I haven’t applied for any fanlisting in ages because of the same.
  3. People’s expectations seem to keep rising and rising. I have no idea what people expect now, but that’s because I’ve purposely avoided knowing what they are, now. I want to make Enth better so much, and I have a lot of ideas on how to do that; but can you imagine how many will complain about what happened to this feature, or why is this doing this now, or I’m not moving because it’s a pain to upgrade. These are certainly all part and parcel of getting a script up for others to download, but little ol’ me feels overwhelmed.

I feel it’s sad that the reason why I worked on Enthusiast (that is, fanlisting) became something I avoided or felt guilty about doing because of Enthusiast.

I’ve gone through months and months of agonizing about this. The fact that I do have other things on my plate doesn’t help with the indecision and the pressure that I was getting, too. When I finally made the decision to put Enth on hold, I finally felt that I could breathe easier.

And thus, there you have it. Enthusiast is officially on hold. All development is stalled, I haven’t looked at any Enth code in months. It doesn’t mean to say I will never go back to it, but it won’t be for a good while. :) Maybe when I can get back into the fanlistings world, eh?

If you have any questions, concerns, or any general comments about Enth (or anything else dev-related I have done), please feel free to comment and ask. (Don’t ask me for troubleshooting support though ;) that doesn’t change, haha!)

11 Comments

Hello world!

Welcome to Whimsical.Nu! I’ve long been itching to do something new, and considering my rather lackluster involvement in anything hobbyistic online recently, I’ve decided to pretty much change everything up. The best result of this is a new domain, and something that I feel closely matches a large part of who I am. ;)

As a result, Whimsical will be my personal blog where I attempt to reconcile different parts of who I am: the geek who is in love with Web and tech, the reader who loves getting lost in books, the writer who is still trying to be courageous enough to dare to write, and the gamer who loves both casual games and RPGs.

This change does come with a cost, however; a number of my websites will soon be retiring, or taking a significant backseat.

  1. Scripts.Indisguise.Org will return to its “roots”; it will be back to a script archive, and scripts will move to an “as is” stage. This is one of the saddest changes I’ll be doing; I don’t know when (or even if) I’ll come back to linkware scriptwriting. Entries have been moved over; comments are closed on these entries.
  2. Seasonal Plume will also take a backseat, and will be “shut down” with a link back to here. I won’t be letting it go (ah, the memories!) but until I figure out what to do with it, it will be… well, existing. Entries have been moved over here, but comments are closed.

Naturally, you can still see me over at my personal journal. The difference between that journal and this blog lies in precisely how they’re called; the journal is writing for myself but to an audience, and this blog is writing for an audience.

I realize that this change may concern a number of you who are interested in Indiscripts and/or Enthusiast. I’d like to go into more detail on what may happen to both, but it will need to be for some other time. Please check back sometime!

As for new things, I’ve added a “Gamer” category. At the moment there is nothing there (hee), but for a while now I’ve been sucked into playing World of Warcraft, which I have been studiously avoiding ever since it went out. Being a bit of a gamer back in college, I just knew it would take up a lot of my time if I started. WOW isn’t the only thing I play, although it’s the only patently “gamer”-esque game I play. My iPhone has three pages full of games, and I’ve deleted about half of the ones I’ve played. ;)

Well, so that’s the new Whimsical blog, please excuse any exposed plumbing you come across while I continue to do a bit of spring cleaning! It can’t help to tell me about it, as well. I’ll get everything scrubbed and polished soon enough. ;)

3 Comments

FF: CSS Optimization Tips

A lot can be gained in terms of website performance by the wise use of cascading stylesheets and styles on the website, and these are relatively easy things to accomplish. They revolve around styles and stylesheet placement.

Stylesheets at the top

One important rule is placing stylesheets at the top, within the HEAD tags. While most browsers will load all styles eventually regardless of placement on the page, putting styles in the HEAD helps the page load progressively, giving users visual feedback that hey, something is loading. One of the worst things that could happen if your styles aren’t in the <head> tag is that the page does load–but there are no styles attached to your HTML elements, and then the page flickers to include the styles. It’s like going out without your clothes on, and then going back in to put them on.

Externalizing stylesheets

Styles can be included in the page source code itself in two ways: either within <style>...</style> tags, or within the style attribute of an HTML element. These are the “easiest” to do, however, it’s better if you put style rules in an external .css file, for a number of reasons:

  1. CSS files can be cached for users, and subsequent returns to your page serves the CSS from the user’s cache instead of asking your server for a copy for download. Your page file size is smaller since it doesn’t have style rules associated with it, and the external stylesheet itself isn’t downloaded on subsequent visits if it’s stored in the visitor’s cache.
  2. Other pages on your website can reuse this same external stylesheet. The optimization gains to this obviously means that all your pages will have a smaller size since there aren’t any styles on the source code itself. The development gains, however, are even better: one change in one file can update all your styles for your pages.

If your website uses a lot of inline styles, it may be quite a challenge to move them out to external stylesheets. It will usually mean a lot of editing and updating of files, the complexity of which depends on how fragmented your styles are.

Linking stylesheets instead of importing

There are two ways of including external stylesheets: via the use of the <link> tag, or @import. The former links your stylesheet to your page, and the latter imports one stylesheet into another. The two ways look like below:

<link href="styles.css" type="text/css">
<style type="text/css">@import url("styles.css");</style>

@import can be used to hide styles from earlier browsers, but in Internet Explorer, it behaves the same as using <link> at the bottom of the page–which pretty much negates the above best practices I’ve talked about.

CSS expressions are evil

Okay, so Internet Explorer is quirky. Sometimes CSS expressions seem to be the only way to fix it–I’ve seen a couple of IE fixes/hacks that require CSS expressions. They look similar to:

width:expression(document.body.clientWidth > 799? "800px": "auto" );

Unfortunately, they’re run pretty much every time the user interacts with the page: they’re run on page render, on browser resize, on page scroll, or even if the mouse moves over the page. If one needs to dynamically set styles, use JavaScript. If you really, really need to use an expression, use one that, in the end, overrides the style declaration so that it’s only run once.

IE filters are also evil

The most frequent use nowadays of IE CSS filters are to fix PNG images in Internet Explorer 6 via the AlphaImageLoader filter:

<div style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='pngimage.png',sizingMethod='scale');"></div>

However, this filter stops rendering and freezes the browser while the image is being downloaded, and since it’s done per element and not per image, each time this element shows up in the browser, you’ll get a bit of a freeze. It’s better to gracefully degrade to using PNG8 which works fine in IE6. If there’s no way out of using the AlphaImageLoader filter, user the underscore hack (_filter) or other IE6-only hacks to keep the style rule limited to IE6 users.

Good luck with optimizing your stylesheets! You can take a look at the other posts in this optimization series below:

  1. Website Optimization
  2. Minimizing HTTP Requests

2 Comments