SlideShare a Scribd company logo
1 of 42
Download to read offline
Doris Chen Ph.D.
Developer Evangelist
Microsoft
doris.chen@microsoft.com
@doristchen
Building Web Sites that
Work Everywhere
Who am I?
 Developer Evangelist at Microsoft based in Silicon
Valley, CA
 Blog: http://blogs.msdn.com/b/dorischen/
 Twitter @doristchen
 Email: doris.chen@microsoft.com
 Has over 18 years of experience in the software industry
focusing on web technologies
 Spoke and published widely at OSCON, Fluent, HTML5
DevConf, JavaOne, O'Reilly, Silicon Valley Code Camp,
and worldwide User Groups meetings
 Doris received her Ph.D. from the University of California
at Los Angeles (UCLA)
Agenda
PAGE 3
Cross Browser Testing
Browser Detection and User Agent
Polyfills and Fallbacks
Summary
Feature Detection
CSS3 and Vendor Prefixes
Cross Browser Testing
4
MICROSOFT CONFIDENTIAL
Interoperable intersection
TheMobileWeb
Testing Tools
 Site Scan (Free)
 Reports back on common coding problems
 https://dev.windows.com/en-us/microsoft-edge/tools/staticscan/
 Browser screenshots (Free)
 Take screenshots of your site in a selection of common browsers and devices
 https://dev.windows.com/en-us/microsoft-edge/tools/screenshots/
 Windows virtual machines (Free)
 free downloads of Windows virtual machines used to test IE6 - IE11
 Need to have a platform for hosting virtual machines: VirtualBox, VMware Fusion
and Parallels
 https://dev.windows.com/en-us/microsoft-edge/tools/vms/windows/
 BrowserStack
 A paid online service that gives you access to hundreds of virtual machines
 Quickly test sites from your browser without installing any actual virtual
machines
 Supports local tunneling, so your site doesn't have to be live
 http://www.browserstack.com/
Testing Tools
Demo
CSS3 and Vendor Prefixes
12
Vendor Prefixes
 Browser vendors oftentimes use vendor-specific prefixes to
implement new features before they are W3C
recommendations
 Once a feature or property is a W3C recommendation,
browsers usually will support the non-prefixed versions
 Examples of vendor prefixes:
 Vendor prefixes are still needed to support older browser
versions, even after the browser vendors have adopted the
non-prefixed versions in newer versions
13
-ms-
-moz-
-o-
-webkit-
Microsoft
Mozilla
Opera
Safari and other WebKit-based browsers
When to Use CSS Prefixes
Common properties & values that need prefixed:
animation
box-sizing
Flexbox layout module properties
CSS regions
transition
transform
CSS grid layout
filter
calc() unit value
16
When to NOT Use Prefixes
Common properties that don't need prefixed:
border-radius
box-shadow
font-face
opacity
text-shadow
pointer-events
max-height
min-height
17
Prefix Tools
 Autoprefixer
 Parses CSS files and adds appropriate vendor prefixes
 Allows you to write CSS without worrying about what prefixes
you should use
 Vendor prefixes are pulled from caniuse.com
 Autoprefixer is a "post-processor", meaning it runs after your
Sass, Stylus or Less has been compiled
 Use Autoprefixer with Grunt
 https://autoprefixer.github.io/
 -prefix-free
 Use only unprefixed CSS properties
 Adding the current browser’s prefix to any CSS
 http://leaverou.github.io/prefixfree/#test-drive
18
Prefix tools
Demo
Browser Detection and User Agent
22
Browser Fragmentation
Fragmentation
 Varying Levels of Support
 Across browsers
 Across browser versions
 New versions released
constantly
 Browser detection doesn’t
work
 Fixes based on assumptions
 Full-time job tracking
changes
Browser Detection: User Agent
 Each browser User Agent through the years tried to
mimic others
 Lead to very complicated logic when UA sniffing
 Many browsers try to act like other browsers to claim
they support each other
 In the past, the user agent string was used to change
code per browser (sometimes via a JavaScript plugin)
 No longer a recommended technique
 Much better technique is to use feature detection
26
User-Agent Strings
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/39.0.2171.71 Safari/537.36 Edge/12.0
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.1.25 (KHTML, like Gecko)
Version/8.0 Safari/600.1.25
Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/40.0.2214.93 Safari/537.36
Mozilla/5.0 (Windows NT 10.0; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
User Agent Sniffing
 Very inexact and can easily be spoofed
 You can end up with very messy browser testing logic:
if (ie) {
if (ie.version === 7) { ... }
} else if (firefox) {
...
} else { ... } // and on and on
 Much less maintainable as browsers evolve
31
Feature Detection
Feature Detection
 Based on what browsers support, not their versions
 Check for the feature you want to use
 Object, Method, Property, Behavior
 Detect for standards-based features
first
 Browsers often support both standards and
legacy
 Standards are your most stable ground to build
upon
 Dynamically load custom code to mimic missing
features
Why not Check for a
Browser?
// If not IE then use addEventListener…
if (navigator.userAgent.indexOf("MSIE") == -1) {
window.addEventListener( “load”, popMessage, false );
} else if (window.attachEvent) {
window.attachEvent( “onload”, popMessage);
}
Bad
Why not Check for a
Browser?
if (window.addEventListener) {
window.addEventListener( “load”, popMessage,
false );
} else if (window.attachEvent) {
window.attachEvent( “onload”, popMessage);
}
Good
Feature Detection
 Best option in my opinion for this…
 http://www.modernizr.com/
 Best feature detection Support
 Detects:
 All major HTML5 features
 All major CSS3 features
 Constantly updated
 Can create a bundle of the tests needed
 Utilize one of the many Modernizr test scripts
 Create a custom script
 Also has polyfills to keep older browsers
supported
Get Custom Build
function(){
var
sheet, bool,
head = docHead || docElement,
style = document.createElement("style"),
impl = document.implementation || { hasFeature: function() { return false; } };
style.type = 'text/css';
head.insertBefore(style, head.firstChild);
sheet = style.sheet || style.styleSheet;
var supportAtRule = impl.hasFeature('CSS2', '') ?
function(rule) {
if (!(sheet && rule)) return false;
var result = false;
try {
sheet.insertRule(rule, 0);
result = (/src/i).test(sheet.cssRules[0].cssText);
sheet.deleteRule(sheet.cssRules.length - 1);
} catch(e) { }
return result;
} :
function(rule) {
if (!(sheet && rule)) return false;
sheet.cssText = rule;
return sheet.cssText.length !== 0 && (/src/i).test(sheet.cssText) &&
sheet.cssText
.replace(/r+|n+/g, '')
.indexOf(rule.split(' ')[0]) === 0;
};
bool = supportAtRule('@font-face { font-family: "font"; src: url(data:,); }');
head.removeChild(style);
return bool;
};
Test for @font-face
You can do this
Test for @font-face
Or ….
if (Modernizr.fontface){
…
}
Demo
Polyfills and Fallbacks
Polyfills
 What are they?
 Typically JavaScript, HTML & CSS code
 What do they do?
 Provides support for missing features
 When do you use them?
 Use them to fallback gracefully or mimic
functionality
 Modernizr will polyfill HTML5 elements automatically
 Help load polyfills for nearly every feature it detects
 Create your own polyfill, or use existing ones
Example Manual Polyfill
if (!window.localStorage) {
window.localStorage = {
getItem: function (key) { /* ... */ },
setItem: function (key, val) { /* ... */ },
clear: function () { /* ... */ }
/* ... */
};
}
53
Example Polyfill with Modernizr
Modernizr.load({
test: Modernizr.geolocation,
yep: 'geo.js',
nope: 'geo-polyfill.js'
});
54
Polyfills: Examples
Video Tags
HTML5 Video & Audio
<audio <video
src= src= The url to the audio or video
width= The width of the video element
height= The height of the video element
poster= The url to the thumbnail of the video
preload= preload= (none, metadata, auto) Start downloading
autoplay autoplay Audio or video should play immediately
loop loop Audio or video should return to start and play
controls controls Will show controls (play, pause, scrub bar)
> >
… …
</audio> </video>
Compatibility Table
HTML5 Audio
MP3
audio
support
Yes
Yes Yes Yes Yes Yes
WAV PCM
audio
support
Yes
No Yes Yes Yes Yes
AAC audio
format
Yes
Yes Yes(*) Yes Yes Yes
Compatibility Table
HTML5 <video>
VP8
(WebM)
video
support
Yes (*)
Yes
Yes No (*) Yes Yes
H.264
video
format
(MPEG-4)
Yes
Yes Yes Yes Yes
Ogg/
Theora
Consider No Yes No Yes Yes
Elements With Fall Backs
PAGE 60
Browsers won’t render elements
they don’t understand...
But, they will render what’s
between those elements
For example:
<video src=“video.mp4”>
What will it render?
</video>
HTML5 <video> : Degrading Gracefully
<video src="video.mp4" poster="movie.jpg"
height="480" width="640"
autoplay autobuffer controls loop>
<!-- Flash/Silverlight video here -->
<script type="text/javascript">
var so = new SWFObject(“video.swf”);
so.addParam("allowFullScreen","true");
so.addVariable("autostart","true");
…
</script>
</video>
 Multiple video sources to support multiple browsers
Plugin Free Experience:
http://www.worldstarhiphop.com/vi
deos/video.php?v=wshhNPy952Q9
wUk3n353
Demo
Take Away
 Avoid browser detection, User Agent Sniffing
 Browsers change
 Varying levels of feature support across all major
browsers
 Use feature detection
 Check for the feature you want to use
 Detect for standards first
 Use Modernizr – http://modernizr.com
 Cleaner code & they’ve done the work for you
 Polyfills and Fallbacks
 mimics a standard API to avoid a rewrite

More Related Content

What's hot

High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
Julien Lecomte
 
Responsive Layout Frameworks for XPages Application UI
Responsive Layout Frameworks for XPages Application UIResponsive Layout Frameworks for XPages Application UI
Responsive Layout Frameworks for XPages Application UI
Chris Toohey
 
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1
James Pearce
 

What's hot (20)

Cartegraph Live HTML, CSS, JavaScript and jQuery Training
Cartegraph Live HTML, CSS, JavaScript and jQuery TrainingCartegraph Live HTML, CSS, JavaScript and jQuery Training
Cartegraph Live HTML, CSS, JavaScript and jQuery Training
 
jQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & TricksjQuery Proven Performance Tips & Tricks
jQuery Proven Performance Tips & Tricks
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
C# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASPC# Advanced L09-HTML5+ASP
C# Advanced L09-HTML5+ASP
 
High Performance Ajax Applications
High Performance Ajax ApplicationsHigh Performance Ajax Applications
High Performance Ajax Applications
 
Responsive Layout Frameworks for XPages Application UI
Responsive Layout Frameworks for XPages Application UIResponsive Layout Frameworks for XPages Application UI
Responsive Layout Frameworks for XPages Application UI
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
Js Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform betterJs Saturday 2013 your jQuery could perform better
Js Saturday 2013 your jQuery could perform better
 
HTML5 and the dawn of rich mobile web applications
HTML5 and the dawn of rich mobile web applicationsHTML5 and the dawn of rich mobile web applications
HTML5 and the dawn of rich mobile web applications
 
[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS[2015/2016] Require JS and Handlebars JS
[2015/2016] Require JS and Handlebars JS
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Apache Cordova 4.x
Apache Cordova 4.xApache Cordova 4.x
Apache Cordova 4.x
 
Modern development paradigms
Modern development paradigmsModern development paradigms
Modern development paradigms
 
Keypoints html5
Keypoints html5Keypoints html5
Keypoints html5
 
HTML5 & CSS3 refresher for mobile apps
HTML5 & CSS3 refresher for mobile appsHTML5 & CSS3 refresher for mobile apps
HTML5 & CSS3 refresher for mobile apps
 
Backbone JS for mobile apps
Backbone JS for mobile appsBackbone JS for mobile apps
Backbone JS for mobile apps
 
JsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery TemplatesJsViews - Next Generation jQuery Templates
JsViews - Next Generation jQuery Templates
 
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1
 
Building an HTML5 Video Player
Building an HTML5 Video PlayerBuilding an HTML5 Video Player
Building an HTML5 Video Player
 

Similar to Building Web Sites that Work Everywhere

HTML5 vs Silverlight
HTML5 vs SilverlightHTML5 vs Silverlight
HTML5 vs Silverlight
Matt Casto
 
HTML5 and CSS3 Techniques You Can Use Today
HTML5 and CSS3 Techniques You Can Use TodayHTML5 and CSS3 Techniques You Can Use Today
HTML5 and CSS3 Techniques You Can Use Today
Todd Anglin
 

Similar to Building Web Sites that Work Everywhere (20)

Echo HTML5
Echo HTML5Echo HTML5
Echo HTML5
 
Session on Selenium 4 : What’s coming our way? by Hitesh Prajapati
Session on Selenium 4 : What’s coming our way? by Hitesh PrajapatiSession on Selenium 4 : What’s coming our way? by Hitesh Prajapati
Session on Selenium 4 : What’s coming our way? by Hitesh Prajapati
 
Selenium 4 - What's coming our way - v1.0.pptx
Selenium 4 - What's coming our way - v1.0.pptxSelenium 4 - What's coming our way - v1.0.pptx
Selenium 4 - What's coming our way - v1.0.pptx
 
HTML5 vs Silverlight
HTML5 vs SilverlightHTML5 vs Silverlight
HTML5 vs Silverlight
 
Vs2005p
Vs2005pVs2005p
Vs2005p
 
Quest to the best test automation for low code development platform kherrazi ...
Quest to the best test automation for low code development platform kherrazi ...Quest to the best test automation for low code development platform kherrazi ...
Quest to the best test automation for low code development platform kherrazi ...
 
HTML5 and CSS3 Techniques You Can Use Today
HTML5 and CSS3 Techniques You Can Use TodayHTML5 and CSS3 Techniques You Can Use Today
HTML5 and CSS3 Techniques You Can Use Today
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
 
Html5 & less css
Html5 & less cssHtml5 & less css
Html5 & less css
 
Joomla Day Austin Part 4
Joomla Day Austin Part 4Joomla Day Austin Part 4
Joomla Day Austin Part 4
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
 
Get Ahead with HTML5 on Moible
Get Ahead with HTML5 on MoibleGet Ahead with HTML5 on Moible
Get Ahead with HTML5 on Moible
 
Intro to mobile web application development
Intro to mobile web application developmentIntro to mobile web application development
Intro to mobile web application development
 
Ethical hacking Chapter 10 - Exploiting Web Servers - Eric Vanderburg
Ethical hacking   Chapter 10 - Exploiting Web Servers - Eric VanderburgEthical hacking   Chapter 10 - Exploiting Web Servers - Eric Vanderburg
Ethical hacking Chapter 10 - Exploiting Web Servers - Eric Vanderburg
 
Robot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs IntegrationRobot Framework Introduction & Sauce Labs Integration
Robot Framework Introduction & Sauce Labs Integration
 
Selenium Tutorial for Beginners - TIB Academy
Selenium Tutorial for Beginners - TIB AcademySelenium Tutorial for Beginners - TIB Academy
Selenium Tutorial for Beginners - TIB Academy
 
HTML5 Intoduction for Web Developers
HTML5 Intoduction for Web DevelopersHTML5 Intoduction for Web Developers
HTML5 Intoduction for Web Developers
 
HTML5 Bootcamp: Essential HTML, CSS, & JavaScript
HTML5 Bootcamp: Essential HTML, CSS, & JavaScriptHTML5 Bootcamp: Essential HTML, CSS, & JavaScript
HTML5 Bootcamp: Essential HTML, CSS, & JavaScript
 
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
Familiar HTML5 - 事例とサンプルコードから学ぶ 身近で普通に使わているHTML5
 

More from Doris Chen

Wins8 appfoforweb fluent
Wins8 appfoforweb fluentWins8 appfoforweb fluent
Wins8 appfoforweb fluent
Doris Chen
 
Dive Into HTML5
Dive Into HTML5Dive Into HTML5
Dive Into HTML5
Doris Chen
 

More from Doris Chen (20)

OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
 
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
 
What Web Developers Need to Know to Develop Native HTML5/JS Apps
What Web Developers Need to Know to Develop Native HTML5/JS AppsWhat Web Developers Need to Know to Develop Native HTML5/JS Apps
What Web Developers Need to Know to Develop Native HTML5/JS Apps
 
Windows 8 Opportunity
Windows 8 OpportunityWindows 8 Opportunity
Windows 8 Opportunity
 
Wins8 appfoforweb fluent
Wins8 appfoforweb fluentWins8 appfoforweb fluent
Wins8 appfoforweb fluent
 
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
 
What Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 AppsWhat Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 Apps
 
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
 
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
 
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
 
Dive Into HTML5
Dive Into HTML5Dive Into HTML5
Dive Into HTML5
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
 
HTML 5 Development for Windows Phone and Desktop
HTML 5 Development for Windows Phone and DesktopHTML 5 Development for Windows Phone and Desktop
HTML 5 Development for Windows Phone and Desktop
 
Dive into HTML5: SVG and Canvas
Dive into HTML5: SVG and CanvasDive into HTML5: SVG and Canvas
Dive into HTML5: SVG and Canvas
 
Performance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best PracticesPerformance Optimization and JavaScript Best Practices
Performance Optimization and JavaScript Best Practices
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
Develop Netflix Movie Search App using jQuery, OData, JSONP and Netflix Techn...
 

Recently uploaded

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
 

Recently uploaded (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
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, ...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
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
 
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...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 

Building Web Sites that Work Everywhere

  • 1. Doris Chen Ph.D. Developer Evangelist Microsoft doris.chen@microsoft.com @doristchen Building Web Sites that Work Everywhere
  • 2. Who am I?  Developer Evangelist at Microsoft based in Silicon Valley, CA  Blog: http://blogs.msdn.com/b/dorischen/  Twitter @doristchen  Email: doris.chen@microsoft.com  Has over 18 years of experience in the software industry focusing on web technologies  Spoke and published widely at OSCON, Fluent, HTML5 DevConf, JavaOne, O'Reilly, Silicon Valley Code Camp, and worldwide User Groups meetings  Doris received her Ph.D. from the University of California at Los Angeles (UCLA)
  • 3. Agenda PAGE 3 Cross Browser Testing Browser Detection and User Agent Polyfills and Fallbacks Summary Feature Detection CSS3 and Vendor Prefixes
  • 5.
  • 7. Testing Tools  Site Scan (Free)  Reports back on common coding problems  https://dev.windows.com/en-us/microsoft-edge/tools/staticscan/  Browser screenshots (Free)  Take screenshots of your site in a selection of common browsers and devices  https://dev.windows.com/en-us/microsoft-edge/tools/screenshots/  Windows virtual machines (Free)  free downloads of Windows virtual machines used to test IE6 - IE11  Need to have a platform for hosting virtual machines: VirtualBox, VMware Fusion and Parallels  https://dev.windows.com/en-us/microsoft-edge/tools/vms/windows/  BrowserStack  A paid online service that gives you access to hundreds of virtual machines  Quickly test sites from your browser without installing any actual virtual machines  Supports local tunneling, so your site doesn't have to be live  http://www.browserstack.com/
  • 9. CSS3 and Vendor Prefixes 12
  • 10. Vendor Prefixes  Browser vendors oftentimes use vendor-specific prefixes to implement new features before they are W3C recommendations  Once a feature or property is a W3C recommendation, browsers usually will support the non-prefixed versions  Examples of vendor prefixes:  Vendor prefixes are still needed to support older browser versions, even after the browser vendors have adopted the non-prefixed versions in newer versions 13 -ms- -moz- -o- -webkit- Microsoft Mozilla Opera Safari and other WebKit-based browsers
  • 11. When to Use CSS Prefixes Common properties & values that need prefixed: animation box-sizing Flexbox layout module properties CSS regions transition transform CSS grid layout filter calc() unit value 16
  • 12. When to NOT Use Prefixes Common properties that don't need prefixed: border-radius box-shadow font-face opacity text-shadow pointer-events max-height min-height 17
  • 13. Prefix Tools  Autoprefixer  Parses CSS files and adds appropriate vendor prefixes  Allows you to write CSS without worrying about what prefixes you should use  Vendor prefixes are pulled from caniuse.com  Autoprefixer is a "post-processor", meaning it runs after your Sass, Stylus or Less has been compiled  Use Autoprefixer with Grunt  https://autoprefixer.github.io/  -prefix-free  Use only unprefixed CSS properties  Adding the current browser’s prefix to any CSS  http://leaverou.github.io/prefixfree/#test-drive 18
  • 15. Browser Detection and User Agent 22
  • 17. Fragmentation  Varying Levels of Support  Across browsers  Across browser versions  New versions released constantly  Browser detection doesn’t work  Fixes based on assumptions  Full-time job tracking changes
  • 18. Browser Detection: User Agent  Each browser User Agent through the years tried to mimic others  Lead to very complicated logic when UA sniffing  Many browsers try to act like other browsers to claim they support each other  In the past, the user agent string was used to change code per browser (sometimes via a JavaScript plugin)  No longer a recommended technique  Much better technique is to use feature detection 26
  • 19. User-Agent Strings Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36 Edge/12.0 Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/600.1.25 (KHTML, like Gecko) Version/8.0 Safari/600.1.25 Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.93 Safari/537.36 Mozilla/5.0 (Windows NT 10.0; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
  • 20. User Agent Sniffing  Very inexact and can easily be spoofed  You can end up with very messy browser testing logic: if (ie) { if (ie.version === 7) { ... } } else if (firefox) { ... } else { ... } // and on and on  Much less maintainable as browsers evolve 31
  • 22. Feature Detection  Based on what browsers support, not their versions  Check for the feature you want to use  Object, Method, Property, Behavior  Detect for standards-based features first  Browsers often support both standards and legacy  Standards are your most stable ground to build upon  Dynamically load custom code to mimic missing features
  • 23. Why not Check for a Browser? // If not IE then use addEventListener… if (navigator.userAgent.indexOf("MSIE") == -1) { window.addEventListener( “load”, popMessage, false ); } else if (window.attachEvent) { window.attachEvent( “onload”, popMessage); } Bad
  • 24. Why not Check for a Browser? if (window.addEventListener) { window.addEventListener( “load”, popMessage, false ); } else if (window.attachEvent) { window.attachEvent( “onload”, popMessage); } Good
  • 25. Feature Detection  Best option in my opinion for this…  http://www.modernizr.com/
  • 26.  Best feature detection Support  Detects:  All major HTML5 features  All major CSS3 features  Constantly updated  Can create a bundle of the tests needed  Utilize one of the many Modernizr test scripts  Create a custom script  Also has polyfills to keep older browsers supported
  • 28. function(){ var sheet, bool, head = docHead || docElement, style = document.createElement("style"), impl = document.implementation || { hasFeature: function() { return false; } }; style.type = 'text/css'; head.insertBefore(style, head.firstChild); sheet = style.sheet || style.styleSheet; var supportAtRule = impl.hasFeature('CSS2', '') ? function(rule) { if (!(sheet && rule)) return false; var result = false; try { sheet.insertRule(rule, 0); result = (/src/i).test(sheet.cssRules[0].cssText); sheet.deleteRule(sheet.cssRules.length - 1); } catch(e) { } return result; } : function(rule) { if (!(sheet && rule)) return false; sheet.cssText = rule; return sheet.cssText.length !== 0 && (/src/i).test(sheet.cssText) && sheet.cssText .replace(/r+|n+/g, '') .indexOf(rule.split(' ')[0]) === 0; }; bool = supportAtRule('@font-face { font-family: "font"; src: url(data:,); }'); head.removeChild(style); return bool; }; Test for @font-face You can do this
  • 29. Test for @font-face Or …. if (Modernizr.fontface){ … }
  • 30. Demo
  • 32. Polyfills  What are they?  Typically JavaScript, HTML & CSS code  What do they do?  Provides support for missing features  When do you use them?  Use them to fallback gracefully or mimic functionality  Modernizr will polyfill HTML5 elements automatically  Help load polyfills for nearly every feature it detects  Create your own polyfill, or use existing ones
  • 33. Example Manual Polyfill if (!window.localStorage) { window.localStorage = { getItem: function (key) { /* ... */ }, setItem: function (key, val) { /* ... */ }, clear: function () { /* ... */ } /* ... */ }; } 53
  • 34. Example Polyfill with Modernizr Modernizr.load({ test: Modernizr.geolocation, yep: 'geo.js', nope: 'geo-polyfill.js' }); 54
  • 36. HTML5 Video & Audio <audio <video src= src= The url to the audio or video width= The width of the video element height= The height of the video element poster= The url to the thumbnail of the video preload= preload= (none, metadata, auto) Start downloading autoplay autoplay Audio or video should play immediately loop loop Audio or video should return to start and play controls controls Will show controls (play, pause, scrub bar) > > … … </audio> </video>
  • 37. Compatibility Table HTML5 Audio MP3 audio support Yes Yes Yes Yes Yes Yes WAV PCM audio support Yes No Yes Yes Yes Yes AAC audio format Yes Yes Yes(*) Yes Yes Yes
  • 38. Compatibility Table HTML5 <video> VP8 (WebM) video support Yes (*) Yes Yes No (*) Yes Yes H.264 video format (MPEG-4) Yes Yes Yes Yes Yes Ogg/ Theora Consider No Yes No Yes Yes
  • 39. Elements With Fall Backs PAGE 60 Browsers won’t render elements they don’t understand... But, they will render what’s between those elements For example: <video src=“video.mp4”> What will it render? </video>
  • 40. HTML5 <video> : Degrading Gracefully <video src="video.mp4" poster="movie.jpg" height="480" width="640" autoplay autobuffer controls loop> <!-- Flash/Silverlight video here --> <script type="text/javascript"> var so = new SWFObject(“video.swf”); so.addParam("allowFullScreen","true"); so.addVariable("autostart","true"); … </script> </video>  Multiple video sources to support multiple browsers
  • 42. Take Away  Avoid browser detection, User Agent Sniffing  Browsers change  Varying levels of feature support across all major browsers  Use feature detection  Check for the feature you want to use  Detect for standards first  Use Modernizr – http://modernizr.com  Cleaner code & they’ve done the work for you  Polyfills and Fallbacks  mimics a standard API to avoid a rewrite