http://www.tuicool.com/articles/7jmE7r

Next week I will be presenting at Scala Days . In my talk I will be discussing building reactive applications with two-way (near) real-time communication using the combination of Server Sent Events for providing clients with updates and REST calls for the backchannel. You may be familiar with two examples of this architecture already: BirdWatch and sse-chat . Now I was thinking about potential questions in the Q&A session after the talk. One potential issue that came to mind almost immediately was the support for Internet Explorer . Out of the box, IE does not support Server Sent Events . Personally, I do not care very much about IE support. I have not used it in years prior to researching this article, and only a low single digit percentage of visitors on my blog uses IE. But I understand this can be a showstopper. So if you don’t care about IE support at all, you really don’t need to read any further. Otherwise, bear with me.

So I started looking for Polyfills and found this one . From the description, it should work right away with IE 10 and above, with no changes to the server side required. What I am presenting in this article is a rather blunt fix, changing the JavaScript from the forked polyfill so that:

  • The global EventSource object is only ever replaced if it doesn’t exist. That way I don’t have the burden of checking if this implementation works with all current browsers (and those to come). Rather, the global EventSource object from the polyfill is only created in Internet Explorer.
  • The check for the “correct” ContentType is removed. Out of the box it did not work with Play Framework but without this check it does. I didn’t care much about changing the ContentType on the server side just to make the polyfill happy.

Let’s have a quick look at the code modifications. They are really short.

Conditional Execution of Anonymous Function eventsource.js (lines 18 to 22)

 
/** modified by Matthias Nehlsen on June 9th, 2014 to add
* check without changing the indentation of the rest of
* the file so that changes can more easily be tracked. */
(function (global) {
"use strict";
if (!global.EventSource) { (function (global) {

The block above ensures that the anonymous function creating / replacing the global EventSource object is really only executed when there is no such global object. This is done by wrapping the anonymous function creating the EventSource object in another anoynmous function that does the check. The global EventSource is then created below:

Creating a global EventSource object eventsource.js (lines 481 to 482)

 
   console.log("Using EventSource PolyFill");
global.EventSource = EventSource;

The only other thing to note is that a check for the expected ContentType was disabled as that was incompatible with the out-of-the box behavior of Play Framework’s EventSource implementation:

Check for expected ContentType eventsource.js (lines 225 to 227)

 
/** modified by Matthias Nehlsen on June 9th, 2014 to
* remove incompatible ContentType type check. */
//if (status === 200 && contentTypeRegExp.test(contentType)) {
if (status === 200) {

Then finally all there is left to do is load this modified polyfill in the application, like this:

Loading Polyfill in Play Framework View index.scala.html (line 141)

 
<script src="/assets/javascripts/vendor/eventsource.js"></script>

With this javascript file loaded in the client side application, the application now works with Internet Explorer 10 and 11, with the potential of supporting versions 8 and 9 as well, should someone care to help. Supposedly, some padding at the beginning of an SSE connection is needed. I have no idea how to add this 2K padding, but maybe you, the reader, know how to achieve this? If so, please help. Thanks in advance. I will not fix this, instead I will side with Google. The have dropped support for IE 9 and below last year and I am fine with supporting what Google supports.

Great. Much better having to answer “sorry, IE is not supported at all”. Blaming Microsoft alone is not going to help much when your client demands just this support. Now if you want to use this architecture for a reactive application and your pointy haired boss comes along, demanding support for IE, you can put a smile on your face.

I am happy to have this potential showstopper out of the way. I’ve been meaning to address this problem for a while, I had just been dreading the logistics of setting up a testing environment for IE, and that part was about as annoying as expected. I had to dig out an old IE7 image for VMWare Fusion, copy the 40GB over slow wi-fi and then do all the due updates, with multiple restarts of the VM, of course. Oh how I have missed Windows. I had almost forgotten. How can this take hours for the updates that make me eligible for IE 10 alone? Anyhow, that’s about as much exposure to Internet Explorer as I can deal with. With Internet 10 and 11, the core functionality with the Server Sent Events works fine now.

The Rickshaw time series chart on the upper right in BirdWatch does not seem to work in IE, but that’s not part of the proof that the proposed architecture works with newer versions of IE. I do not plan on spending any more time with making IE 8 and 9 work, but in theory it sounds like that would be possible, according to the documentation of Yaffle’s polyfill . Feel free to fix this in case you know a solution, please. There’s a fork of the polyfill that would happily accept pull requests. Thank you.

Okay, until next time, I hope to see you at Scala Days. Say hi when you see me, please. Matthias

Play Framework, Server Sent Events and Internet Explorer的更多相关文章

  1. IE中无法执行JS脚本 解决WINDOWS SERVER 2008弹出INTERNET EXPLORER增强安全配置正在阻止来自下列网站的内容

    在默认状态下,使用Windows Server 2008系统自带的IE浏览器访问网页内容时,我们时常发现“Internet Explorer增强安全配置正在阻止来自下列网站的内容”的提示导致不能打开网 ...

  2. 如何在Windows Server 2016启用或关闭Internet Explorer增强的安全配置

    一般我们安装完服务器后,开启 Internet Explorer 会发现无法上网或者上网内容被屏蔽掉了 问题的发生原因 在 Windows Server 2016 通常扮演重要的服务器角色,不应该用来 ...

  3. 在Windows Server 2012启用或关闭Internet Explorer增强的安全配置

    在 Windows Sever 2012 中打开 IE 浏览器时,IE10 会出现[已启用 Internet Explorer 增强的安全配置]的提示信息. 在安全性等级中会设置以[高安全性],如果我 ...

  4. Windows Server 2016 关闭Internet Explorer增强的安全配置

    Windows Server 2016 关闭Internet Explorer增强的安全配置 IE11 默认启用 Internet Explorer 增强的安全配置,浏览网页时这个提示十分频繁,是不是 ...

  5. 企业IT管理员IE11升级指南【6】—— Internet Explorer 11面向IT专业人员的常见问题

    企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...

  6. Internet Explorer 安全区域注册表项说明

    引用网址:http://support.microsoft.com/kb/182569/zh-cnInternet Explorer 安全区域设置存储在以下注册表子项下面: HKEY_LOCAL_MA ...

  7. 企业IT管理员IE11升级指南【2】—— Internet Explorer 11 对Adobe Flash的支持

    企业IT管理员IE11升级指南 系列: [1]—— Internet Explorer 11增强保护模式 (EPM) 介绍 [2]—— Internet Explorer 11 对Adobe Flas ...

  8. Selenium2学习-037-WebUI自动化实战实例-IE浏览器显示比例问题:org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. Browser zoom level was set to 94%. It should be set to 100%

    好久没有写博文了,今天在给部门新人演示 Selenium WebDriver 启动其支持的各种浏览器时,启动 IE 时总是无法打开对应的百度网址,页面如下所示:

  9. What is XMLHTTP? How to use security zones in Internet Explorer

    Types of Security Zones Internet Zone This zone contains Web sites that are not on your computer or ...

随机推荐

  1. 【IOS 开发】Object - C 语法 之 流程控制

    1. if 条件语句 if 表达式 : 表达式是一个 整型 或者 布尔型, 0 或者 FALSE 为 FALSE, 大于 0 为 TRUE; 代码示例 : /********************* ...

  2. Java 学习之反射机制“解刨”分解类,并获取内容!

    正常情况下,单纯的做开发是接触不到反射机制的(额,当然并不排除例外的情况了).下面我就对我学到的反射方面的知识做一个小小的总结,旨在复习和以后的查看. 原理分析: 所谓反射就是将一个类当做我们研究的对 ...

  3. mysql filesort 的解决方案

    在explain我们所使用的sql的时候,经常会遇到using filesort这种情况,原以为是由于有相同列值的原因引起,结果昨天看到公司的一个sql,跟同事讨论了下加上自己又做了一些测试,突然发现 ...

  4. 【一天一道LeetCode】#88. Merge Sorted Array

    一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ...

  5. Leetcode_6_ZigZag Conversion

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/41408021 看完这篇文章,你可能会学到到知识如下: (1 ...

  6. thinkpad x260在ubuntu 14.04lts wifi驱动安装 ( ubuntu iwlwifi驱动 都可行 )

    实验室要新购笔记本x260,用于ROS调试,装上ubuntu-ros后,发现wifi不支持. 查阅大量资料,如下: http://www.ubuntu.com/certification/hardwa ...

  7. 【一天一道LeetCode】#50. Pow(x, n)

    一天一道LeetCode系列 (一)题目 Implement pow(x, n). (二)解题 题目很简单,实现x的n次方. /* 需要注意一下几点: 1.n==0时,返回值为1 2.x==1时,返回 ...

  8. 江湖问题研究-- intent传递有没有大小限制,是多少?

    出门一步,便是江湖,江湖上有许多流言. 比如这条: intent传递是有大小限制的,具体在40KB左右. 当然也有传言说是1M左右. 数百头母驴为何半夜惨叫? 小卖部安全套为何屡遭黑手? 女生宿舍内裤 ...

  9. 【翻译】使用Ext JS设计响应式应用程序

    原文:Designing Responsive Applications with Ext JS 在当今这个时代,用户都希望Web应用程序无论在形状还是大小上,既能在桌面电脑,也能在移动设备上使用.使 ...

  10. unity用PUN进行信息交互模块

    using UnityEngine; using System.Collections.Generic; public class MessageChat : Photon.MonoBehaviour ...