2014/05/15

Jquery Ajax loader


$(function () {
                if (window.location.hash){ contentload(window.location.hash);}

                $("body").on("click", "a", function(event){
                    fragment = this.hash; 
                    if(this.hostname == window.location.hostname )
                    {
                        if($(this).attr('data-toggle') != "dropdown" && $(this).attr('target') != "_blank")
                        {
                            var load_url = this.href.split('<?php echo $_SERVER['SERVER_NAME']?>');
                            contentload(load_url[1], true);
                        }
                        return false;
                    }
                });
                
                window.onpopstate = function(event) {
                        load_url = location.href;
                        contentload( load_url, false);
                        console.log("path: " + load_url);
                       
                };
                
        });
        function contentload(load_url, is_link) {
                $("#body-loader").show();
                
                $.ajax({
                    url      : load_url,  
                    success  : function(data) {
                        $('#container-wrapper').html(data);
                        $("#body-loader").hide();
                        if(is_link)
                        {
                            var full_url = '//<?php echo $_SERVER['SERVER_NAME']?>'+load_url;
                            history.pushState({}, 'New URL: ' + full_url, full_url);
                        }
                        load_start();
                    }                     
                });    
        }

Cache header for Apache


<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>


<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>