SlideShare una empresa de Scribd logo
1 de 18
Descargar para leer sin conexión
Abusing Javascript to
speedup mobile web sites.
Mobile browsers are
     dog slow
Only if they are used to render web
sites designed for desktop browsers.

One code for any browser and
device is actually a dream.

Bad code tends to have more impact
on mobile browsers.
Radio networks are
       slow
The main issue is not speed but
latency.

4 Mb downloaded over a single
request: 2 seconds.

Same data downloaded as 20 small
files: 8 seconds.
A 304 reply code is nearly as bad as
a 200

404 replies are rarely cached. Kill
them all.

Proper caching of anything cacheable
is required

Don't overestimate the browser cache
and HTTP keep-alive.
HTML5 cache
         manifest
Doesn't bring much over proper HTTP caching
for online apps.

Everything in the manifest is preloaded even
when useless for the current page. Double-
sided sword.

Requests from a cached page have no referrer.

No granularity: everything depends on the
freshness of the manifest.
Mobile browsers have
   unpredicable caching
         strategy


Even on the same operating system

iOS 4.1 on iPhone 3G doesn't cache
some tiny content that could really
be cached. And that the same OS on
other devices does.
JavaScript to the
     rescue!
Slower may feel
       faster
Mobile devices have small screens.

Load visible content first, and use XHR to
load the rest.

Don't wait until the user scrolls, though.
Latency + tendency to scroll and zoom on
mobile devices would make the page feel
slow.

Provide feedback.
JS + HTTP caching
   = not so bad

Don't repeat yourself: use static JS to
render common, static fragments.

Use XHR to render dynamic parts that
are not immediately visible.

Different parts can have different
expiration.
HTTP cache is quite
  unpredictable
No control over actual eviction.

Might feel good, even for large
requests, until everything is evicted.

The server controls the cache, not
the client (which could come in
handy to avoid inconsistencies).
Localstorage is the
     real shit
Seamlessly keeps over 2.5 Mb of data
per domain.

Mostly persistent.

Provides a flexible client-controlled
cache for any resource.

Trivial to implement.
if (window.localStorage["geoapi_js-v5"]) {
 window.eval(window.localStorage["geoapi_js-v5"]);
} else {
 var xhr = new XMLHttpRequest;
 xhr.onreadystatechange = function() {
  if (this.readyState != 4) {
    return;
  }
  if (this.status != 200) {
    alert("Erreur reseau: " + this.status);
    return;
  }
  try {
    window.localStorage["geoapi_js-v5"] = this.responseText;
  } catch (e) { }
  window.eval(this.responseText);
 };
 xhr.open("GET", "geoapi-v5.js", true);
 xhr.send();
}
Client-side
fragment caching
Dramatically improves performance of a
non-AJAXified page with minor changes.

Use localstorage to store common
fragments.

Tell the server about known fragments so
that only identifiers from the previous
page are sent, in place of the actual
content.
<!doctype html>
<html>
<head>
 <title>Transparent client-side fragment cache demo</title>
</head>
<body>
<!--fragment navbar-290d996311209f1897516b2caa2cc611-->
 <nav>
   Navigation bar
 </nav>
<!--/fragment-->
<!--fragment ads-bd779001f9cad4bfb74e563eb6bbf5c5-->
 <div id="ads">
   Ads
 </div>
<!--/fragment-->
 <section id="hey">
   I ain't no <a href="/">fragment</a>!
 </section>
 <script src="disco.js"></script>
</body>
</html>
<section id="hey">
   I ain't no <a href="/">fragment</a>!
 </section>


gets dynamically rewritten as:


 <section id="hey">
   I ain't no <a href="/?
_fragments=navbar-290d996311209f1897516b2caa2cc611+ads-
bd779001f9cad4bfb74e563eb6bbf5c5">fragment</a>!
 </section>
<!doctype html>
<html>
<head>
 <title>Transparent client-side fragment cache demo</title>
</head>
<body>
<!--cached navbar-290d996311209f1897516b2caa2cc611-->
<!--cached ads-bd779001f9cad4bfb74e563eb6bbf5c5-->
 <section id="hey">
   I ain't no <a href="/">fragment</a>!
 </section>
 <script src="disco.js"></script>
</body>
</html>
http://00f.net/2010/09/22/
 transparent-client-side-
     fragment-cache/
Frank
@jedisct1

Más contenido relacionado

La actualidad más candente

MongoDB Memory Management Demystified
MongoDB Memory Management DemystifiedMongoDB Memory Management Demystified
MongoDB Memory Management Demystified
MongoDB
 
Webinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControlWebinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControl
Severalnines
 
MongoDB Hacks of Frustration
MongoDB Hacks of FrustrationMongoDB Hacks of Frustration
MongoDB Hacks of Frustration
MongoDB
 
Distributed computing in browsers as client side attack
Distributed computing in browsers as client side attackDistributed computing in browsers as client side attack
Distributed computing in browsers as client side attack
Ivan Novikov
 

La actualidad más candente (18)

Mongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricksMongo performance tuning: tips and tricks
Mongo performance tuning: tips and tricks
 
DDoS: Practical Survival Guide
DDoS: Practical Survival GuideDDoS: Practical Survival Guide
DDoS: Practical Survival Guide
 
MongoDB Memory Management Demystified
MongoDB Memory Management DemystifiedMongoDB Memory Management Demystified
MongoDB Memory Management Demystified
 
Breaking the Oracle Tie; High Performance OLTP and Analytics Using MongoDB
Breaking the Oracle Tie; High Performance OLTP and Analytics Using MongoDBBreaking the Oracle Tie; High Performance OLTP and Analytics Using MongoDB
Breaking the Oracle Tie; High Performance OLTP and Analytics Using MongoDB
 
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
 
Observability tips for HAProxy
Observability tips for HAProxyObservability tips for HAProxy
Observability tips for HAProxy
 
Systems Introspection
Systems IntrospectionSystems Introspection
Systems Introspection
 
Web acceleration mechanics
Web acceleration mechanicsWeb acceleration mechanics
Web acceleration mechanics
 
E forensic series
E forensic seriesE forensic series
E forensic series
 
Time series databases
Time series databasesTime series databases
Time series databases
 
Webinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControlWebinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControl
 
Scaling with mongo db - SF Mongo User Group 7-19-2011
Scaling with mongo db - SF Mongo User Group 7-19-2011Scaling with mongo db - SF Mongo User Group 7-19-2011
Scaling with mongo db - SF Mongo User Group 7-19-2011
 
Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?Real time web: is there a life without socket.io and node.js?
Real time web: is there a life without socket.io and node.js?
 
MongoDB Hacks of Frustration
MongoDB Hacks of FrustrationMongoDB Hacks of Frustration
MongoDB Hacks of Frustration
 
Distributed computing in browsers as client side attack
Distributed computing in browsers as client side attackDistributed computing in browsers as client side attack
Distributed computing in browsers as client side attack
 
HAProxy as Egress Controller
HAProxy as Egress ControllerHAProxy as Egress Controller
HAProxy as Egress Controller
 
HTTP 2.0 Why, How and When
HTTP 2.0 Why, How and WhenHTTP 2.0 Why, How and When
HTTP 2.0 Why, How and When
 
Webinar slides "Building Real-Time Collaborative Web Applications"
Webinar slides "Building Real-Time Collaborative Web Applications"Webinar slides "Building Real-Time Collaborative Web Applications"
Webinar slides "Building Real-Time Collaborative Web Applications"
 

Similar a Abusing Javascript to speedup mobile web sites

Krug Fat Client
Krug Fat ClientKrug Fat Client
Krug Fat Client
Paul Klipp
 
77739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-10377739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-103
shashank_ibm
 
Persistent Offline Storage White
Persistent Offline Storage WhitePersistent Offline Storage White
Persistent Offline Storage White
Alexei White
 

Similar a Abusing Javascript to speedup mobile web sites (20)

your browser, my storage
your browser, my storageyour browser, my storage
your browser, my storage
 
improve website performance
improve website performanceimprove website performance
improve website performance
 
Your browser, your storage (extended version)
Your browser, your storage (extended version)Your browser, your storage (extended version)
Your browser, your storage (extended version)
 
The 5 most common reasons for a slow WordPress site and how to fix them
The 5 most common reasons for a slow WordPress site and how to fix themThe 5 most common reasons for a slow WordPress site and how to fix them
The 5 most common reasons for a slow WordPress site and how to fix them
 
Caching By Nyros Developer
Caching By Nyros DeveloperCaching By Nyros Developer
Caching By Nyros Developer
 
Mobile Web
Mobile WebMobile Web
Mobile Web
 
your browser, your storage
your browser, your storageyour browser, your storage
your browser, your storage
 
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
 
Krug Fat Client
Krug Fat ClientKrug Fat Client
Krug Fat Client
 
Ror caching
Ror cachingRor caching
Ror caching
 
Bt0070 operating systems 2
Bt0070 operating systems  2Bt0070 operating systems  2
Bt0070 operating systems 2
 
Web Speed And Scalability
Web Speed And ScalabilityWeb Speed And Scalability
Web Speed And Scalability
 
Web Performance in the Age of HTTP/2 - FEDay Conference, Guangzhou, China 19/...
Web Performance in the Age of HTTP/2 - FEDay Conference, Guangzhou, China 19/...Web Performance in the Age of HTTP/2 - FEDay Conference, Guangzhou, China 19/...
Web Performance in the Age of HTTP/2 - FEDay Conference, Guangzhou, China 19/...
 
Your browser, my storage
Your browser, my storageYour browser, my storage
Your browser, my storage
 
Startups to Scale
Startups to ScaleStartups to Scale
Startups to Scale
 
77739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-10377739818 troubleshooting-web-logic-103
77739818 troubleshooting-web-logic-103
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with Flowdock
 
Persistent Offline Storage White
Persistent Offline Storage WhitePersistent Offline Storage White
Persistent Offline Storage White
 
Joomla! Performance on Steroids
Joomla! Performance on SteroidsJoomla! Performance on Steroids
Joomla! Performance on Steroids
 
Building great mobile apps: Somethings you might want to know
Building great mobile apps: Somethings you might want to knowBuilding great mobile apps: Somethings you might want to know
Building great mobile apps: Somethings you might want to know
 

Más de Frank Denis (6)

El Passo - Privacy-preserving single sign on
El Passo - Privacy-preserving single sign onEl Passo - Privacy-preserving single sign on
El Passo - Privacy-preserving single sign on
 
Improving password-based authentication
Improving password-based authenticationImproving password-based authentication
Improving password-based authentication
 
This domain name will self-destruct tomorrow
This domain name will self-destruct tomorrowThis domain name will self-destruct tomorrow
This domain name will self-destruct tomorrow
 
An introduction to Pincaster
An introduction to PincasterAn introduction to Pincaster
An introduction to Pincaster
 
Graphs
GraphsGraphs
Graphs
 
Redis - (nosqlfr meetup #2)
Redis - (nosqlfr meetup #2) Redis - (nosqlfr meetup #2)
Redis - (nosqlfr meetup #2)
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Abusing Javascript to speedup mobile web sites

  • 1. Abusing Javascript to speedup mobile web sites.
  • 2. Mobile browsers are dog slow Only if they are used to render web sites designed for desktop browsers. One code for any browser and device is actually a dream. Bad code tends to have more impact on mobile browsers.
  • 3. Radio networks are slow The main issue is not speed but latency. 4 Mb downloaded over a single request: 2 seconds. Same data downloaded as 20 small files: 8 seconds.
  • 4. A 304 reply code is nearly as bad as a 200 404 replies are rarely cached. Kill them all. Proper caching of anything cacheable is required Don't overestimate the browser cache and HTTP keep-alive.
  • 5. HTML5 cache manifest Doesn't bring much over proper HTTP caching for online apps. Everything in the manifest is preloaded even when useless for the current page. Double- sided sword. Requests from a cached page have no referrer. No granularity: everything depends on the freshness of the manifest.
  • 6. Mobile browsers have unpredicable caching strategy Even on the same operating system iOS 4.1 on iPhone 3G doesn't cache some tiny content that could really be cached. And that the same OS on other devices does.
  • 8. Slower may feel faster Mobile devices have small screens. Load visible content first, and use XHR to load the rest. Don't wait until the user scrolls, though. Latency + tendency to scroll and zoom on mobile devices would make the page feel slow. Provide feedback.
  • 9. JS + HTTP caching = not so bad Don't repeat yourself: use static JS to render common, static fragments. Use XHR to render dynamic parts that are not immediately visible. Different parts can have different expiration.
  • 10. HTTP cache is quite unpredictable No control over actual eviction. Might feel good, even for large requests, until everything is evicted. The server controls the cache, not the client (which could come in handy to avoid inconsistencies).
  • 11. Localstorage is the real shit Seamlessly keeps over 2.5 Mb of data per domain. Mostly persistent. Provides a flexible client-controlled cache for any resource. Trivial to implement.
  • 12. if (window.localStorage["geoapi_js-v5"]) {  window.eval(window.localStorage["geoapi_js-v5"]); } else {  var xhr = new XMLHttpRequest;  xhr.onreadystatechange = function() {   if (this.readyState != 4) {     return;   }   if (this.status != 200) {     alert("Erreur reseau: " + this.status);     return;   }   try {     window.localStorage["geoapi_js-v5"] = this.responseText;   } catch (e) { }   window.eval(this.responseText);  };  xhr.open("GET", "geoapi-v5.js", true);  xhr.send(); }
  • 13. Client-side fragment caching Dramatically improves performance of a non-AJAXified page with minor changes. Use localstorage to store common fragments. Tell the server about known fragments so that only identifiers from the previous page are sent, in place of the actual content.
  • 14. <!doctype html> <html> <head> <title>Transparent client-side fragment cache demo</title> </head> <body> <!--fragment navbar-290d996311209f1897516b2caa2cc611--> <nav> Navigation bar </nav> <!--/fragment--> <!--fragment ads-bd779001f9cad4bfb74e563eb6bbf5c5--> <div id="ads"> Ads </div> <!--/fragment--> <section id="hey"> I ain't no <a href="/">fragment</a>! </section> <script src="disco.js"></script> </body> </html>
  • 15. <section id="hey"> I ain't no <a href="/">fragment</a>! </section> gets dynamically rewritten as: <section id="hey"> I ain't no <a href="/? _fragments=navbar-290d996311209f1897516b2caa2cc611+ads- bd779001f9cad4bfb74e563eb6bbf5c5">fragment</a>! </section>
  • 16. <!doctype html> <html> <head> <title>Transparent client-side fragment cache demo</title> </head> <body> <!--cached navbar-290d996311209f1897516b2caa2cc611--> <!--cached ads-bd779001f9cad4bfb74e563eb6bbf5c5--> <section id="hey"> I ain't no <a href="/">fragment</a>! </section> <script src="disco.js"></script> </body> </html>