Website Speed Optimization

Notices

Client-side caching Browser and proxy cache

HTTP Headers

  1. expires
  2. cache-control
  3. etag
  4. vary
  5. pragma
  6. Surrogate-Control (new)

 

2. CACHE CONTROL

Public resources:

  • will be accessible from a public-facing Force.com Site

Private resources:

  • require you to be authenticated with a Session Id (eg, in the org, in a portal, logged into a Site)

 

 

Caching methods:

  1. HTML meta tags
  2. PHP
  3. Apache .htaccess

 

PHP
header('Expires: Thu, 01-Jan-70 00:00:01 GMT'); header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); header('Cache-Control: no-store, no-cache, must-revalidate'); header('Cache-Control: post-check=0, pre-check=0', false); header('Pragma: no-cache');

 

 

Negative: If cache enabled cant see the number of visits correctly.

Cache validators: cUrl

 

Questions:

1How to cache google maps, songs, youtube videos?

2No aching with <?php header("Cache-Control: no-cache, must-revalidate");

 

 

To cache specific type use in .htaccess

<Directory "/data/www/public_html/images/">
<IfModule mod_expires.c>
# Add Expiration
ExpiresActive On
ExpiresDefault "access plus 1 week"
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/php "access plus 1 day"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/javascript "access plus 1 week"
ExpiresByType application/x-javascript "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 week"
ExpiresByType image/ico "access plus 1 week"
ExpiresByType text/xml "access plus 1 day"
</IfModule>
</Directory>

 

 Server-side caching

- DB cache via PHP script

- Apache cache: mod_cache, mod_file_cache

- memcached, PDO, APC, wincache

Other methods:

 1. First call cURL with cronjob every period of time: #/usr/bin/curl -s http://localhost/?starttime=2012.01.01 > /cache/localhost.2012.01.01.html . After that we can use htmlcompressor to remove white spaces from HTML document. The method is good for updating cache with cron job on certain period of time.

 

 

Caching servers

  1. memcached - RAM - key-value storage 2003. do 1MB
  2. redis - RAM + Hard disk 2009. -do 512MB
  3. MySQL with storage type MEMORY
  4. varnish - RAM - caches complete web page -- HTTP gateway cache
  5. APC - RAM - data caching & op-code caching (data caching nd php precompilation)
  6. eAccelator: php pre compilation
  7. xcache: php pre compilation

 

 

There are 2 types of caching terminology thrown around in PHP.

First is an optcode cache: http://en.wikipedia.org/wiki/PHP_accelerator

Second is a data cache: http://simas.posterous.com/php-data-caching-techniques

A few of the technologies can cross boundaries into both realms, but the basics behind them are simple. The idea is: Keep as much data in ram and precompiled because compiling and HD seeks are very expensive processes. HD Seeks can be done to find a file to compile / query the DB to get data / looking for a temp file, and every time that happens it slows down the user experience.

other: Apache Cassandra vs MongoDB vs CouchDB vs Redis vs Riak vs HBase vs Couchbase vs OrientDB vs Aerospike vs Neo4j vs Hypertable vs ElasticSearch vs Accumulo vs VoltDB vs Scalaris