Join Justin Yost for an in-depth discussion in this video Why should you optimize your websites?, part of PHP: Performance Optimization.
- [Instructor] To start our course on performance optimization, we should first discuss why it matters to optimize your websites. The easy answer is that a faster site is better than different, slower website. Think about it this way. Who ever asks for a slower website? Or for that matter, who ever asks for a slow just about anything? No one asks for a slower website, but if we ignore performance, we are inherently asking for a slower site by not prioritizing speed.
Let's better answer the question of what specifically a faster site gets us. In terms of something you can take to your bosses, what are the actual reasons to focus on optimization of a website? First, what is optimization? Optimization means a lot of different things. Mostly what we're going to focus on in this course is the speed of the website, so that when someone calls it up, that information is presented to that person as fast as we possibly can.
Let's start by looking at some research into why we care about the speed of a website. As in, does this stuff really matter? In June of 2009, Google published some information into one of their experiments. Speed matters for Google web search, in which Google demonstrated that slowing down their site just 100 milliseconds caused a decrease in the number of searches users performed. Quote, "Increasing web search latency 100 to 400 ms "reduces the daily number of searches per user "by 0.2% to 0.6%" For users who had a 400 millisecond delay added on to their web searches, they performed less searches, even after the delay was removed.
In other words, having a slow site can change people's perception of even Google, and cause them to use your site and Google differently. What we can infer from that is speed matters all the time. Anytime your site is slower, your users may not enjoy using it as much and presumably, you want them on your site and enjoying using your site. Perhaps more importantly, if you have slowness on your site, the memory of that slowness may persist, even after being resolved.
Perhaps you are thinking, "Well, that's just Google." Google's know for their speed. More importantly, when does it typically have to do a Google search? What about a platform like Amazon, when you need to buy something? Does that really make a difference? Greg Linden, who released a summary of what Amazon reports said that every 100 milliseconds of a delay causes a loss of one percent of sales. What about some even more recent data? The Financial Times reported, and here I'm quoting, "Test results showed that for every one second increase "in speed, our engagement score increased by five percent.
"In subscription and ads inventory, this translated "into millions in revenue. "Speed therefore became a principal element of this site." An even more recent one in the Wall Street Journal in July of 2017, reported on publishers who decreased the number of ads on their site and actually saw their revenue increase as a result of users sharing more content. The viewed more pages and actually clicked on the ads even more than before. Here's the take-away.
The slower the site, the less people will want to use the site. Perhaps more importantly, if your site is too slow, you may actually be preventing certain groups from using your site. The corollary of this, however, is also true. A faster site means more people using and using the site more. At the end of the day, we want to focus on not just making your site not slow. We want to focus on making your site fast. We should also keep in mind, at the end of the day, it's easy to optimize for yourself, and make the site feel fast enough for you on your expensive fairly modern machine with a reasonable internet connection, presumably.
However, it's a lot harder to optimize for the person in Africa using a five year-old phone over a cell connection, and when the nearest server that they're talking to is all the way in Europe or North America. Optimization isn't, and shouldn't be a one time process. Optimization is a thing you need to worry about all day. Each new feature should have an understanding of how it changes the performance nature of your site. Some parts of optimization are things you can just bolt on and forget.
Some, however, are baked into the underlying architecture of the site. Also, the choices you make about optimizing will be different for each site your build. If you have a single-page application, you will make different choices from a standard Belarc built on a standard CMS. An e-commerce site will also have different choices. All of these choices will inform the decisions that you will take. My goal is that you understand and grasp that optimization matters. I'm going to give you some general principals and a toolkit to help you build a faster website.
- General optimization techniques and tools
- PHP and Xdebug
- Opcode cache
- Optimization in PHP
- Upgrading PHP
- Macro vs. Micro optimization
- HTTP caching
- HTTP compression