Google Mobile First Index
Speed up your web / Apache / SEO
Emirodgar / https://emirodgar.com - @emirodgar
Optimize Apache http web server & web
Check Apache active modules
We need access through SSH in order to execute linux commands
Check Apache active modules with:
● apache2ctl -M
If not activated, we need to turn on expires and headers:
● a2enmod expires
● a2enmod headers
After that, we need to restart the server
● service apache2 restart
Apache .htaccess file
Now we need to edit .htaccess file which is located at the root of our site
(base www dir).
If it doesn’t exist, we can create it through FTP. After that we just need
to add some lines in order to speed up our site. We are going to active:
● Cache-control
● GZIP Compression
● Keep alive
● Etag
.htaccess set cache-control
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/js "access 1 month"
ExpiresByType text/html "access 1 day"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access plus 1 month"
</IfModule>
.htaccess set Etag
Etag helps to use cache memory in a more efficient way. It works like a digital print, it only changes when
a file has changed.
FileETag MTime Size
Check if it is working
.htaccess GZIP compression
<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 handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
Check if it is working
.htaccess set keep-alive
Allow to transfer multiple files between server and browser
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
Check if it is working
.htaccess redirect errors to homepage
This code will help us to redirect all errors to the homepage. Use it carefully. It doesn’t affect the speed
but can help us to handle multiple errors.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /? [L,R=301]
.htaccess prevent hotlinking
As the previous point, it doesn’t affect the load time, but can help us to control our resources preventing
others sites to consume them.
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?emirodgar.com [NC]
RewriteRule .(jpg|jpeg|png|gif|svg)$ https://domain.com/image.jpg [NC,R,L]
Optimize resources
In order to speed up we need to work with
optimized files:
● Compress HTML
● Compress CSS
● Compress JS
● Compress images
Compress and optimize HTML
Compress CSS
Select CSS used
Make sure you only include in your page the CSS styles you are actually
using in the site.
CSS Used is a Chrome plugin that will select the CSS you need (export &
create a new final file). Firefox has similar plugins with the same
functionality.
Compress Javascript
Compress images
We can use one of the several tools we have online:
● https://kraken.io/web-interface
● http://optimizilla.com
● https://compressor.io
● https://tinypng.com
Use a cookieless subdomain as CDN
Let’s create our own CDN (Content Delivery Network). You can also use some service as Cloudflare (free
and paid plans available).
● Create a subdomain of your own domain or use another domain
● Load static files as CSS, JS and images from this new access
Learn more about cookie free domains.
Use a cookieless subdomain as CDN - Analytics
If your are using Google Analytics, make sure you are not generating cookies on the CDN subdomain. For
that, set cookie_domain to none.
Install modpagespeed
You can also install mod_pagespeed in your server. Once installed, learn how to configure it.
cd /tmp
wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb
dpkg -i mod-pagespeed-stable_current_amd64.deb
Check if it is working
Google Mobile First Index
Speed up your web / Apache / SEO
Emirodgar / https://emirodgar.com - @emirodgar

2018 Google Mobile First Index - Speed up Apache & Web for SEO

  • 1.
    Google Mobile FirstIndex Speed up your web / Apache / SEO Emirodgar / https://emirodgar.com - @emirodgar
  • 2.
    Optimize Apache httpweb server & web
  • 3.
    Check Apache activemodules We need access through SSH in order to execute linux commands Check Apache active modules with: ● apache2ctl -M If not activated, we need to turn on expires and headers: ● a2enmod expires ● a2enmod headers After that, we need to restart the server ● service apache2 restart
  • 4.
    Apache .htaccess file Nowwe need to edit .htaccess file which is located at the root of our site (base www dir). If it doesn’t exist, we can create it through FTP. After that we just need to add some lines in order to speed up our site. We are going to active: ● Cache-control ● GZIP Compression ● Keep alive ● Etag
  • 5.
    .htaccess set cache-control <IfModulemod_expires.c> ExpiresActive On ExpiresByType image/jpg "access 1 year" ExpiresByType image/jpeg "access 1 year" ExpiresByType image/gif "access 1 year" ExpiresByType image/png "access 1 year" ExpiresByType text/css "access 1 month" ExpiresByType text/js "access 1 month" ExpiresByType text/html "access 1 day" ExpiresByType application/pdf "access 1 month" ExpiresByType text/x-javascript "access 1 month" ExpiresByType image/x-icon "access 1 year" ExpiresDefault "access plus 1 month" </IfModule>
  • 6.
    .htaccess set Etag Etaghelps to use cache memory in a more efficient way. It works like a digital print, it only changes when a file has changed. FileETag MTime Size
  • 7.
    Check if itis working
  • 8.
    .htaccess GZIP compression <IfModulemod_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 handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.* </IfModule>
  • 9.
    Check if itis working
  • 10.
    .htaccess set keep-alive Allowto transfer multiple files between server and browser <ifModule mod_headers.c> Header set Connection keep-alive </ifModule>
  • 11.
    Check if itis working
  • 12.
    .htaccess redirect errorsto homepage This code will help us to redirect all errors to the homepage. Use it carefully. It doesn’t affect the speed but can help us to handle multiple errors. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /? [L,R=301]
  • 13.
    .htaccess prevent hotlinking Asthe previous point, it doesn’t affect the load time, but can help us to control our resources preventing others sites to consume them. RewriteEngine On RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?emirodgar.com [NC] RewriteRule .(jpg|jpeg|png|gif|svg)$ https://domain.com/image.jpg [NC,R,L]
  • 14.
    Optimize resources In orderto speed up we need to work with optimized files: ● Compress HTML ● Compress CSS ● Compress JS ● Compress images
  • 15.
  • 16.
  • 17.
    Select CSS used Makesure you only include in your page the CSS styles you are actually using in the site. CSS Used is a Chrome plugin that will select the CSS you need (export & create a new final file). Firefox has similar plugins with the same functionality.
  • 18.
  • 19.
    Compress images We canuse one of the several tools we have online: ● https://kraken.io/web-interface ● http://optimizilla.com ● https://compressor.io ● https://tinypng.com
  • 20.
    Use a cookielesssubdomain as CDN Let’s create our own CDN (Content Delivery Network). You can also use some service as Cloudflare (free and paid plans available). ● Create a subdomain of your own domain or use another domain ● Load static files as CSS, JS and images from this new access Learn more about cookie free domains.
  • 21.
    Use a cookielesssubdomain as CDN - Analytics If your are using Google Analytics, make sure you are not generating cookies on the CDN subdomain. For that, set cookie_domain to none.
  • 22.
    Install modpagespeed You canalso install mod_pagespeed in your server. Once installed, learn how to configure it. cd /tmp wget https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_amd64.deb dpkg -i mod-pagespeed-stable_current_amd64.deb
  • 23.
    Check if itis working
  • 26.
    Google Mobile FirstIndex Speed up your web / Apache / SEO Emirodgar / https://emirodgar.com - @emirodgar

Editor's Notes

  • #7 Link: https://httpd.apache.org/docs/2.4/es/mod/core.html
  • #11 Link: https://abdussamad.com/archives/169-Apache-optimization:-KeepAlive-On-or-Off.html
  • #26 Check server response: https://www.sumologic.com/apache/analyzing-response-time/