CONTENTS
Professional Website Performance: Optimizing the Front End and the Back End
Published by
John Wiley & Sons, Inc.
10475 Crosspoint Boulevard
Indianapolis, IN 46256
www.wiley.com
Copyright 2013 by John Wiley & Sons, Inc., Indianapolis, Indiana
Published simultaneously in Canada
ISBN: 978-1-118-48752-5
ISBN: 978-1-118-48751-8 (ebk)
ISBN: 978-1-118-55172-1 (ebk)
ISBN: 978-1-118-55171-4 (ebk)
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions .
Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.
For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com . For more information about Wiley products, visit www.wiley.com .
Library of Congress Control Number: 2012949514
Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc., is not associated with any product or vendor mentioned in this book.
To my wife, Stef, and my parents
ABOUT THE AUTHOR
PETER G. SMITH has been a full-time Linux consultant, web developer, and system administrator, with a particular interest in performance for the past 13 years. Over the years, he has helped a wide range of clients in areas such as front-end performance, load balancing and scalability, and database optimization. Past open source projects include modules for Apache and OSCommerce, a cross-platform IRC client, and contributions to The Linux Documentation Project (TLDP).
ABOUT THE TECHNICAL EDITOR
JOHN PELOQUIN is a software engineer with back-end and front-end experience ranging across web applications of all sizes. Peloquin earned his B.A. in Mathematics from the University of California at Berkeley, and is currently a lead engineer for a healthcare technology startup, where he makes heavy use of MySQL, PHP, and JavaScript. He has edited Professional JavaScript for Web Developers, 3rd Edition by Nicholas Zakas (Indianapolis: Wiley, 2012) and JavaScript 24-Hour Trainer by Jeremy McPeak (Indianapolis: Wiley, 2010). When he is not coding or collecting errata, Peloquin is often found engaged in mathematics, philosophy, or juggling.
CREDITS
EXECUTIVE EDITOR
Carol Long
PROJECT EDITOR
Kevin Shafer
TECHNICAL EDITOR
John Peloquin
PRODUCTION EDITOR
Rosanna Volis
COPY EDITOR
San Dee Phillips
EDITORIAL MANAGER
Mary Beth Wakefield
FREELANCER EDITORIAL MANAGER
Rosemarie Graham
ASSOCIATE DIRECTOR OF MARKETING
David Mayhew
MARKETING MANAGER
Ashley Zurcher
BUSINESS MANAGER
Amy Knies
PRODUCTION MANAGER
Tim Tate
VICE PRESIDENT AND EXECUTIVE GROUP PUBLISHER
Richard Swadley
VICE PRESIDENT AND EXECUTIVE PUBLISHER
Neil Edde
ASSOCIATE PUBLISHER
Jim Minatel
PROJECT COORDINATOR, COVER
Katie Crocker
PROOFREADER
Nancy Carrasco
INDEXER
Robert Swanson
COVER DESIGNER
Ryan Sneed
COVER IMAGE
Henry Price / iStockphoto
ACKNOWLEDGMENTS
A LOT OF PEOPLE HAVE BEEN INVOLVED in making this book happen. Id like to thank everyone at Wiley for their hard work, especially Carol Long for having faith in my original idea and helping me to develop it, and Kevin Shafer, my Project Editor, who patiently helped turn my manuscript into a well-rounded book. Special thanks are also due to John Peloquin, whose technical review proved invaluable.
Id also like to take the opportunity to thank my friends and family for being so supportive over the past few months.
INTRODUCTION
THE PAST DECADE has seen an increased interest in website performance, with businesses of all sizes realizing that even modest changes in page loading times can have a significant effect on their profits. The move toward a faster web has been driven largely by Yahoo! and Google, which have both carried out extensive research on the subject of website performance, and have worked hard to make web masters aware of the benefits.
This book provides valuable information that you must know about website performance optimization from database replication and web server load balancing, to JavaScript profiling and the latest features of Cascading Style Sheets 3 (CSS3). You can discover (perhaps surprising) ways in which your website is under-performing, and learn how to scale out your system as the popularity of your site increases.
WHY SPEED IS IMPORTANT
At first glance, it may seem as if website loading speeds arent terribly important. Of course, it puts off users if they must wait 30 seconds for your page to load. But if loading times are relatively low, isnt that enough? Does shaving off a couple of seconds from loading times actually make that much of a difference? Numerous pieces of research have been carried out on this subject, and the results are quite surprising.