Skip to main content
mod_pagespeed 1.15 — Cyclone Cache, modernized optimizations, IIS + .NET support, and six years of security updates

Local storage cache

Caching

Stores inlined CSS and images in the browser's local storage for repeat visits.

Filter local_storage_cache,inline_css,inline_images · Filter docs

A mod_pagespeed 1.15 filter. ModPageSpeed 2.0 applies it as part of one always-on pipeline, not as a separate switch.

Both frames render identically — that's the goal. The win is in the bytes and requests below, not the look. They're served live by mod_pagespeed 1.15 on demo-httpd-1.1.modpagespeed.com; the optimized frame applies only this filter. Right after a cache purge it may briefly match the original while the worker rewrites it — reload to see the result.

Measured impact

HTTP requests

3 2
−1

What changed in the source

The page's HTML, before and after this filter. Red lines are removed, green lines are added.

                
                  
<html>
<head>
<title>Local Storage Cache Test</title>
- <link rel='stylesheet' href="styles/yellow.css">
+ <script type="text/javascript" data-pagespeed-no-defer>//<![CDATA[ (function(){function e(b){var a=window;if(a.addEventListener)a.addEventListener("load",b,!1);else if(a.attachEvent)a.attachEvent("onload",b);else{var c=a.onload;a.onload=function(){b.call(this);c&&c.call(this)}}}var p=Date.now||function(){return+new Date};window.pagespeed=window.pagespeed||{};var r=window.pagespeed;function t(){this.g=!0}t.prototype.i=function(b){b=parseInt(b.substring(0,b.indexOf(" ")),10);return!isNaN(b)&&b<=p()};t.prototype.hasExpired=t.prototype.i;t.prototype.h=function(b){return b.substring(b.indexOf(" ",b.indexOf(" ")+1)+1)};t.prototype.getData=t.prototype.h;t.prototype.j=function(b){var a=document.getElementsByTagName("script");a=a[a.length-1];a.parentNode.replaceChild(b,a)};t.prototype.replaceLastScript=t.prototype.j; t.prototype.l=function(b){var a=null;try{a=window.localStorage.getItem("pagespeed_lsc_url:"+b)}catch(f){}var c=document.createElement(a?"style":"link");a&&!this.i(a)?(c.type="text/css",c.appendChild(document.createTextNode(this.h(a)))):(c.rel="stylesheet",c.href=b,this.g=!0);this.j(c)};t.prototype.inlineCss=t.prototype.l; t.prototype.o=function(b,a){var c=null;try{c=window.localStorage.getItem("pagespeed_lsc_url:"+b+" pagespeed_lsc_hash:"+a)}catch(d){}var f=document.createElement("img");c&&!this.i(c)?f.src=this.h(c):(f.src=b,this.g=!0);c=2;for(var h=arguments.length;c<h;++c){var k=arguments[c].indexOf("=");f.setAttribute(arguments[c].substring(0,k),arguments[c].substring(k+1))}this.j(f)};t.prototype.inlineImg=t.prototype.o; function u(b,a,c,f){a=document.getElementsByTagName(a);for(var h=0,k=a.length;h<k;++h){var d=a[h],n=d.getAttribute("data-pagespeed-lsc-hash"),g=d.getAttribute("data-pagespeed-lsc-url");if(n&&g){g="pagespeed_lsc_url:"+g;c&&(g+=" pagespeed_lsc_hash:"+n);var l=d.getAttribute("data-pagespeed-lsc-expiry");l=l?(new Date(l)).getTime():"";d=f(d);if(!d){var m=null;try{m=window.localStorage.getItem(g)}catch(q){}m&&(d=b.h(m))}if(d)try{window.localStorage.setItem(g,l+" "+n+" "+d),b.g=!0}catch(q){}}}} function v(b){u(b,"img",!0,function(a){return a.src});u(b,"style",!1,function(a){return a.firstChild?a.firstChild.nodeValue:null})} r.m=function(){var b=new t;r.localStorageCache=b;e(function(){v(b)});e(function(){if(b.g){var a=[],c=[],f=0,h=p(),k=0;try{k=window.localStorage.length}catch(q){}for(var d=0;d<k;++d)try{var n=window.localStorage.key(d);if(!n.indexOf("pagespeed_lsc_url:")){var g=window.localStorage.getItem(n),l=g.indexOf(" "),m=parseInt(g.substring(0,l),10);if(!isNaN(m))if(m<=h){a.push(n);continue}else if(m<f||f==0)f=m;c.push(g.substring(l+1,g.indexOf(" ",l+1)))}}catch(q){}h="";f&&(h="; expires="+(new Date(f)).toUTCString()); document.cookie="_GPSLSC="+c.join("!")+";path=/"+h;d=0;for(k=a.length;d<k;++d)try{window.localStorage.removeItem(a[d])}catch(q){}b.g=!1}})};r.localStorageCacheInit=r.m;})(); pagespeed.localStorageCacheInit(); //]]></script><style data-pagespeed-lsc-url="https://demo-httpd-1.1.modpagespeed.com/mod_pagespeed_example/styles/yellow.css" data-pagespeed-lsc-hash="INwLgsBqR7" data-pagespeed-lsc-expiry="Fri, 24 Jul 2026 14:33:20 GMT">.yellow {background-color: yellow;}
+ </style>
</head>
<body>
<div id="div" class="yellow">I should be on a yellow background ...</div>

Run this on your own site

This is one of 49 filters mod_pagespeed 1.15 applies in place — self-hosted on Apache, nginx, and IIS. Install and run it: it optimizes right away and adds an X-PageSpeed-Warn: unlicensed header until you license it. Production use requires a commercial license — but the software never locks you out.