Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Configuring WordPress for Browser Caching

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 383
    Comment on it

    Hello readers!
    Today we discuss about "How to Leverage Browser Caching in WordPress" (Configuring WordPress For browser caching).

    Browser caching:- Browser caching helps to reduces the request per page in numbers which results to reduce server load. In other words we can say that, Browser caching can help to reduce server load by reducing the number of requests per page.

    Example:- Browsers cache the static files like i.e- Images, CSS, JavaScript etc, on the user's computer. This technique allows the browser to check and see whether files have been changed, instead of simply requesting them.
    For browser caching you can also use plugin(WP Super Cache) to store static pages in your browser. this plugin can be download from the below given url:-
    https://wordpress.org/plugins/wp-super-cache

    Leverage Browser Caching in WordPress via .htaccess

    If you can't use caching then the loading time of your website will increase and it will result in too many load from server. Server caching is bit complex but it provides vast option for caching techniques.
    So, if you want to speed up your caching, then configure your .htaccess file.
    Open up your .htaccess file and paste in the following directives at the top of the file:

    ## EXPIRES CACHING ## 
    <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 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 2 days" 
    </IfModule> 
    ## EXPIRES CACHING ## 
    

    By using the below code, the main static files (images, CSS, PDFs, JS, etc.) will be cached in order to produce faster loading times in the future.
    Every time when we run our website in browser, cleanup and processing operation will generate large amount of cache.
    In WordPress right now there is no way to disable cache. It is good that directive like WP_DISABLE_CACHE is added to control this. it is actually to delete cached object.

    Here is the function below which will clear the cache and stored queries:

    <?php 
    function wp_clean_cache_full() { 
      global $wpdb, $wp_object_cache; 
    
      unset($wp_object_cache->cache); 
      $wp_object_cache->cache = array(); 
      unset($wpdb->queries); 
      $wpdb->queries = array(); 
    } 
    ?>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: