Skip to content

Don't try to support AMD loaders in socket.io#491

Merged
rauchg merged 1 commit intosocketio:masterfrom
adityab:amd-unsupport
Nov 10, 2012
Merged

Don't try to support AMD loaders in socket.io#491
rauchg merged 1 commit intosocketio:masterfrom
adityab:amd-unsupport

Conversation

@adityab
Copy link
Contributor

@adityab adityab commented Nov 9, 2012

The AMD loader support that was recently added pollutes things globally.

While undoubtedly useful, this can cause breakage when used with some other libraries, and it is therefore better to let developers do things their own way.

Case in point - #490, which I can reproduce - using Dojo and NowJS together will always break Dojo's require.

This PR undoes the relevant changes made by #453.

@adityab
Copy link
Contributor Author

adityab commented Nov 10, 2012

/cc @guille , @3rd-Eden .

I understand that this is a much loved feature, but it breaks stuff. Doing things the old way is, however, much simpler than patching socket.io downstream.

@3rd-Eden
Copy link
Contributor

I personally hate AMD, it's pointless bloat to everybody who doesn't use AMD, it doesn't work and it's just pointless. AMD support should be solved in build systems not in libraries. So i'm all +1 on this @guille

And I agree that this needs to be fixed and removed.

rauchg added a commit that referenced this pull request Nov 10, 2012
Don't try to support AMD loaders in socket.io
@rauchg rauchg merged commit 63f1838 into socketio:master Nov 10, 2012
@shimondoodkin
Copy link

my solution to AMD problem:

The library $script.js https://github.com/ded/script.js was an immediate solution for me to convert an HTML file with many JavaScript includes, into one single script, that can be included at the bottom of the page on any website.

I have looked at AMD ... And I think that $script.js solution is a better solution then AMD, simpler and smarter. (might be not a better way to write programs but a better solution)

It adds to the head of HTML a SCRIPT tag element of asynchronous JavaScript. it adds them in the right order. it uses regular callbacks right after the SCRIPT tag has been finished loading.
There is no special API just regular html-javascript way.

Because of adding regular script tags asynchronously I think it's much better then async-AJAX and eval. Because global variables remain global - not become within a function. so No need to change anything in the code, and everything works - and asynchronously! A Solution in minutes instead of hours (as if i had to rewrite everything to AMD).

from this

<div id="container"></div>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/javascripts/layout.js"></script>
<script type="text/javascript" src="/javascripts/nodejs-clone-extend.js"></script>
<!--[if IE]>
<script type="text/javascript" src="/javascripts/FlashCanvas/bin/flashcanvas.js"></script>
<![endif]-->
<script type="text/javascript" src="/javascripts/flotr2/flotr2.min.js"></script>
<script type="text/javascript">
   ...app code fills the container
</script>

to this (includeable littleservice.js):

//insert content of script.min.js   ...

document.write('<!--[if IE]><script type="text/javascript" src="http://site.com:5051/javascripts/FlashCanvas/bin/flashcanvas.js"></script><![endif]-->');
$script('http://site.com:5051/socket.io/socket.io.js', function () {
$script('http://site.com:5051/javascripts/layout.js', function () {
$script('http://site.com:5051/javascripts/nodejs-clone-extend.js', function () {
$script('http://site.com:5051/javascripts/flotr2/flotr2.min.js', function (){
$script('http://site.com:5051/javascripts/chart.js');
})
})
})
})

so i can use it in any web site like this

<!-- start chart --->
<style type="text/css">
  #container{
    width : 90%;
    height: 180px;
    text-align:center;
  }
</style>
<div id="container"></div>
<script type="text/javascript" src="http://site.com:5051/chart.js"></script>
<!-- end chart --->

to my surprise asynchronous loading was much faster then regular html script includes

@sergeylukin
Copy link

When will this become part of latest stable version? We need it for docpad/docpad-plugin-livereload#5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants