Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
matchMedia vs cached matchMedia
(version: 0)
Comparing performance of:
cached vs new vs before
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <style> #before:before { content: "a"; display: none; } @media(min-width: 200px) { #body { background: red; content: "b"; } } @media(min-width: 600px) { #body { background: blue; content: "c"; } } @media(min-width: 1000px) { #body { background: yellow; content: "d"; } } </style> <div id="body"> </div>
Script Preparation code:
mediaMatcher = window.matchMedia("(min-width: 400px)");
Tests:
cached
mediaMatcher.matches;
new
window.matchMedia("(min-width: 400px)").matches;
before
window.getComputedStyle(document.getElementById('body'), ':before').getPropertyValue('content').replace(/\"/g, '');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
cached
new
before
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
matchMedia vs clientWidth
matchMedia vs document.body.clientWidth
addEventListener('resize') + innerWidth VS matchMedia() + matchMedia.addListener() VS Without JS
addEventListener('resize') + innerWidth VS matchMedia() + matchMedia.addListener() VS CSS
Comments
Confirm delete:
Do you really want to delete benchmark?