Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
loading using require.js
// Require.js allows us to configure shortcut alias
// The shim config allows us to configure dependencies for
// scripts that do not call define() to register a module
shim: {
'socketio': {
exports: 'io'
'underscore': {
exports: '_'
'backbone': {
deps: [
exports: 'Backbone'
paths: {
jquery: 'jquery.min',
underscore: 'lodash.min',
backbone: 'backbone',
socketio: '../',
], function( $, Backbone, io ) {
var socket = io.connect('http://localhost');
socket.on('news', function (data) {
socket.emit('my other event', { my: 'data' });
//Ready to write Backbone Models and communication protocol in here :)
Copy link

nullivex commented Nov 5, 2013

Thanks this helped me get that working.

Copy link

CurtisSV commented Dec 23, 2013

This saved me a lot of frustration! Thanks!

Copy link

felixhammerl commented Jan 13, 2014

my lazyness thanks you :)

Copy link

korczis commented Jan 23, 2014


Copy link

srlm-io commented Apr 15, 2014

The most recent version of (0.9.16) is AMD compatible, so you don't need to do much at all. For my application the server is on a different domain, so we can include the path argument to pull the script from the correct location, but if it's on the same domain you could just require \\

    // serves up the script ready to go. has the following lines:
    // if (typeof define === "function" && define.amd) {
    //   define([], function () { return io; });
    // }

    // All we need to do is tell it the path to our server:
        paths: {
            socketio: ''

    require(['socketio'], function(io) {
        var socket = io.connect('');
        console.log('socket connected');

Copy link

hongshan5 commented May 5, 2014

thanks very much :)

Copy link

EderRoger commented Jul 2, 2014

Thanks !! Solved my issue!

Copy link

flyfly6 commented Aug 7, 2014

great! Thanks very much!

Copy link

chul-hyun commented Aug 19, 2014

Thanks!! ><

Copy link

lwiechec commented Aug 29, 2014

yup, thanks!

Copy link

herlon214 commented Apr 28, 2015

thanks 😄

Copy link

web-jenezis commented Nov 29, 2015

thanks a lot for this tip!!!

Copy link

ryang420 commented Jan 21, 2016

Thanks! Fixed my issue.

Copy link

freemh commented Jan 29, 2016

Thank you.

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