Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Continuing to optimized a web site, I'm using Chrome's Dev Tool add-on for Page Speed.

I've been able to do a good bit of performance tuning thanks to its suggestions, but these two have me perplexed:

I'm being told I need specify character set, but I have this in all my documents (meta tag below). It's within the head, does it need to be done prior to the HTML tag? If so, what's the syntax?

<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />

Second one I'm getting dinged on is deferring of Javascript.

I know back in the day you could add a defer="defer" to the JS, but I don't think that's valid, nor does that satisfy the Page Speed validators. How do I defer JS?

Typically my sites have jQuery linked to Google's CDN, and then an overarching local site.js loaded right after the jQuery core, like so:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="/lib/js/site.js"></script>
share|improve this question

1 Answer 1

up vote 4 down vote accepted

Ideally, the Content-type should be specified in HTTP headers (and the text/html part almost certainly is). Failing that, the declaration must be within the first 1024 bytes (usually 1024 characters) of the document.

The best way to ensure this is putting it right after the <head> tag. If you are using HTML5 you can simply use <meta charset="utf-8">.

For Javascript, the best way to effectively "defer" it is to place the scripts at the bottom of the page, before </body>. This way the page will load and not be held back by scripts loading.

This may not be easily possible in some site architectures, so do not worry if it's not. Just keep the number and size of scripts to a reasonable level.

share|improve this answer
    
Added <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> and Page Speed still says that no char set is specified in http headers. –  Keefer Dec 9 '11 at 15:56
    
You can also use $(document).ready() or window.onload to defer execution of code, though putting the script element at the end of the document is still the best way to defer the downloading of the script. I'm not sure if all browsers support the defer attribute yet. –  Lèse majesté Dec 9 '11 at 16:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.