
Internet Marketing and AI blog

## Start browser caching ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## End browser caching ##
You will want to change the timelines to whatever makes sense for you. The longer the timeframe the less often a resource will have to be downloaded however if you replace a resource (say - your logo) with a file of the same name the old one will display as the browser believes it has the file. To get around this, when you change a resource like your logo, if you simply give it a new name the browser will understand it hasn't seen the file before and get the new one.
The first step of this process is the easiest, simply resize them. One of the most frustrating things I see in my travels is sites that use images larger than the size they're displaying on a page. Massive 5000px by 3000px images shrunk down in the image call to 500 by 300 or some such thing. This is where the largest savings occurs in image size optimization. All you need for this stage is a good image editing program (or even a not good one for that matter). Resize the image to the size it will display as on the page. No more and no less.
After that the next step is to optimize the image for itself. Images tend to include a lot of extraneous code in them from camera data to using a larger color palette than necessary thus adding bits to each pixel that aren't necessary. But enough about that, how do you fix it? There are many ways using standard image editing programs such as Photoshop (read details on this here) but assuming you don't use Photoshop or a similar tool I've found TinyPNG quite handy in a pinch.
Just process your image through it and reupload them (after insuring that the image quality is still suitable and nothing went wrong of course) and your problem will be solved.
Enabling compression on a web page is exactly what it sounds like, it's basically shrinking a file and sending it to be expanded on the other end. It's a very similar idea to creating a Zip file of your page and sending it to be unziped by the browser on the other end. It reduces the bandwidth needed dramatically and thus increases the speed of your site.
Similar to enabling browser caching, enabling compression on an Apache server is done easily via the .htaccess file. And here's the code to add:
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_include mime ^text/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_include handler ^cgi-script$
</ifModule>
This tells the server to compress your files using the gzip format and is supported by all major browsers. If for some reason it doesn't work however you can try the following:
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
Clicking on the link in the sentence, "Download optimized image, JavaScript, and CSS resources for this page." will download the images, JavaScripts and style sheets in their optimized forms. I've found better success with the image optimization using the techniques above however this method does work well for both JavaScripts and CSS. You'll want to remember to make a backup of your current (easily read) style sheet to use for editing should you need it in the future (or if something goes wrong obviously). Once you've done that simply upload the new files to your server and they'll be minified.
You can also enter your file content into tools like:
CSS Minifier
or
JavaScript Minifier
You may have noticed that I haven't included HTML minification here. HTML minification has a lot more room for issues. You can use tools like this one at GitHub but be aware that the room for error is greater here and full backups and complete testing are required.
And last but not least, the reduction of the server response time. Basically what we're talking about here is reducing the time between the initial request from a browser for a web page and the time the server begins sending all the 1s and 0s necessary to display it. Let's use a simple example to illustrate where the problem comes from. Let's imagine that your web server can support 1000 resource calls per second (this assumes all resources are the same which they are not but it works for the example) without slowing down. Now, if your web page has 100 resources (images, scripts, style sheets, etc.) then your site can support 10 page requests per second. And maybe that was enough when you first got on the web and were the only visitor to your site but as your visitor count grew so too did the page views. So now you have 20 pages being requested every second and you're getting the "Reduce server response time" notice. So what do you do? There are three options:
1 - reduce the number of calls to the server, or
2 - increase the performance of the server, or
3 - ignore the problem and torture your visitors
Assuming #3 isn't an option let's look at the second option first. If you're getting the "Reduce server response time" message you can contact your hosting company and simply upgrade the server to include more RAM, CPU allocation and/or faster hard drives to address. These are generally the bottleneck points and giving your site more resources will undoubtedly solve the problem and is never a bad idea BUT it may hide another issue ...
Fundamentally the problem arises from having more resource calls than a server can handle and the more visitors to a site the more amplified the issue. Before upgrading your server the first step should always be to assess what resources are being called and question whether they are necessary and if they are, if there's a better way to deploy them.
The first place to start is at a tool like Web Page Test which will pull your page and provide statistics on each resource it calls. I prefer the waterfall view. This view displays a list of all recourse and when you hover over them it displays details on how long it took to locate and load the resource. But what do you do about it?
1 - Eliminate any unnecessary resources. If you find resources being called that are unnecessary remove them. Often we find unused plugins, old tracking scripts and other clutter on a web page. Removing this clutter is stage one. This can also mean limiting resource calls to specific pages. If you're tracking clicks on a page using CrazyEgg or other similar tool only add it to the page being tracked not every page on your site.
2 - After you've eliminated unnecessary resources we need to look at way of speeding up those that remain. Assuming you've minified your CSS and scripts and optimized your images and are still having this problem it's time to look to a Content Delivery Network (CDN). You will want to discuss options with your hosting provider or developer as each host and web setup is different.
3 - At this stage you have minimized the number of resource calls and optimized those that remain. If you are still getting the message it's time to upgrade your hosting. The reason I recommend optimization first is that going straight to upgrading your server simply masks the problem and as traffic grows you'll need to upgrade sooner again. Dealing with the root of the issue first allows you to save on hosting and know you've got the fastest setup possible.