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>

1 Answer 1


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.

  • 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
    Commented Dec 9, 2011 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. Commented Dec 9, 2011 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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