Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ES5 shim with jquery/mootools/prototype

I stumbled across this project: https://github.com/termi/ES5-DOM-SHIM which provides almost full ES5 support in all browsers including old IEs.

I've been using it in pure JS projects, but now I have to include jquery/mootools/prototype in a project (that uses High Charts).

Even just including the jquery script causes errors to be thrown in IE8 along with this shim. How can I keep the best of both worlds?

My document head looks like this:

<!--[if lte IE 8]>
<script src="/js/a.ie8.js"></script>
<![endif]-->
<script src="/js/a.js"></script>
<script src="/js/jquery.1.8.2.js"></script>
<script src="/js/main.js"></script>
like image 867
Greg Avatar asked Nov 09 '12 10:11

Greg


2 Answers

Make sure you're using the correct html structure, e.g.:

<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <!--[if lte IE 8]>
    <script src="a.ie8.js"></script>
    <![endif]-->
    <script src="a.js"></script>
    <script src="jquery.1.8.2.js"></script>
    <script src="main.js"></script>
</head>
<body>

</body>

When I tested your structure (without doctype) I was also getting an error in IE.

like image 197
Dziad Borowy Avatar answered Nov 14 '22 13:11

Dziad Borowy


This is a late answer, and probably it doesn't address your main issue. So at the risk of getting downvoted...

As far I can tell from the Github project ES5-DOM-SHIM not only provides shim for ES5 features but also tries to shim DOM features that are not available on IE. This is very useful if you wish to program directly with the DOM API.

jQuery also provides a compatibility layer that does feature check in order to fill implementation gaps (so you don't need a DOM polyfill if your code only uses jQuery).

Mixing both doesn't seem to be a good idea because:

  • You are duplicating a lot of polyfill logic in your JS.
  • Polyfill have limitations, so if jQuery thinks that your browser fully supports a feature when it doesn't you can get some unexpected errors.

If you want JavaScript polyfills only, try with https://github.com/kriskowal/es5-shim (note ES5-DOM-SHIM is based on it)

like image 21
Diego Avatar answered Nov 14 '22 15:11

Diego