Curl requests for run.js even if bundle.js is there

96 views
Skip to first unread message

Bulat Sh

unread,
Nov 28, 2013, 7:48:53 AM11/28/13
to cuj...@googlegroups.com
Hi everyone!  It's me again.

I've made a bundle.js using cram.js and I rewrote my script tag so it's rendered by django like this:
<script data-curl-run="/static/bundled/client.js,/static/run_client.js" src="/static/js/curl.js"></script>

My run_client.js file:

var cfg = {
    baseUrl: "/static/js",
    packages: {
        rpc: {
            location: "dist/rpc",
            main: "jquery.jsonrpc.min.js",
            config: {
                loader: "curl/loader/legacy",
                exports: "jQuery",
                requires: ["jquery"]
            }
        }
    },
    paths: {
        "jquery": "jquery.min.js",
        "underscore": "lodash.min.js",
        "backbone": {
            location: "backbone.js",
            config: {
                loader: "curl/loader/legacy",
                exports: "Backbone.noConflict()",
                requires: ["jquery", "underscore"]
            }
        },
        "marionette": "backbone.marionette.min.js",
        "styles": "../css",
        "alertify": "alertify.min.js"
    }
};

curl(cfg, ["app/client"]).then(function(client) {
    cfg.paths.bundles = app.rootUrl + "bundles/"
    curl(cfg)
    client.start()
});

I redefine baseUrl during compilation on the server with production.json file in cram's --config param:
{
"baseUrl": "./js"
}

Curl downloads client.js and run_client as well and calls client.start() twice which is not really a good thing, because it causes Marionette rerender everything.
Removing curl(cfg) and above line doesn't help, anyway I need them, because app.rootUrl is not known during "cram"ming.

Is there a way to fix this?

unscriptable

unread,
Nov 28, 2013, 2:41:13 PM11/28/13
to cuj...@googlegroups.com
Hey Bulat, put some breakpoints in the bootscript function in curl.js. I suspect there's an exception happening when loading or evaluating client.js. If so, you can catch it and report it here.

-- John

unscriptable

unread,
Nov 28, 2013, 2:42:36 PM11/28/13
to cuj...@googlegroups.com

Bulat Sh

unread,
Dec 2, 2013, 3:37:38 AM12/2/13
to cuj...@googlegroups.com
I'm sorry, I still can't figure this out.  

so I had to work it around using django template. if debug mode is on it loads run_client.js and if is not bundled client.js is loaded throw different script src.


Second issue is that these lines 
cfg.paths.bundles = app.rootUrl + "bundles/"
curl(cfg)
will not work as expected, because curl modifies cfg somewhere inside, so when I call config again path to jquery.jsonrpc.min.js gets corrupted. I get somewhat like /static/js/dist/rpc/rpc/rpc/jquery.jsonrpc.min.js.
So I have to clone initial cfg object and use original one to reconfigure curl.

unscriptable

unread,
Dec 3, 2013, 11:03:08 AM12/3/13
to cuj...@googlegroups.com
Hey Bulat,


On Monday, December 2, 2013 3:37:38 AM UTC-5, Bulat Sh wrote:
I'm sorry, I still can't figure this out.  

so I had to work it around using django template. if debug mode is on it loads run_client.js and if is not bundled client.js is loaded throw different script src.

OK. Glad you've got something working for now. :)

 
Second issue is that these lines 
cfg.paths.bundles = app.rootUrl + "bundles/"
curl(cfg)
will not work as expected, because curl modifies cfg somewhere inside, so when I call config again path to jquery.jsonrpc.min.js gets corrupted. I get somewhat like /static/js/dist/rpc/rpc/rpc/jquery.jsonrpc.min.js.
So I have to clone initial cfg object and use original one to reconfigure curl.

You do not need to clone or inherit from your own config.  curl.js's configs inherit from previous configs.  If you configure curl a second time, it will add or override properties from the previous config.  (Hm... I guess that's not well documented. :/)  The following code snippet will add or override the path, but leave the rest of the config the same:

curl({ paths: { bundles: app.rootUrl + "bundles/" } });

It sounds like this is what you want?

-- John

Bulat Sh

unread,
Jan 14, 2014, 12:45:19 PM1/14/14
to cuj...@googlegroups.com
Hi,  

curl({ paths: { bundles: app.rootUrl + "bundles/" } });

It sounds like this is what you want?.

That's exactly right. And 100% works.

So now I have my app completely deployed.  It has 7500 lines of code ( and constantly growing ), which is packed into 6 files by cram for different user interfaces. With cram I could make my code modular, which is great.

What is really nice about cram is it's plugins for text, css and legacy scripts. I was able to translate my whole app step by step, so I fully migrated into AMD without any problem. So I add new features all the time, while 
part of my code is in amd modules, and other parts are in legacy script files.

So I want to thank you all guys for helping me to get into this and those of you, who's working on this great piece of software and especially unscriptable. 

unscriptable

unread,
Jan 14, 2014, 12:49:24 PM1/14/14
to cuj...@googlegroups.com
Very glad you got this working, Bulat!

Also: very interesting that you managed to migrate a large codebase.  Many people have tried and given up.

If you're the blogging type, please consider writing a blog post about it.  Problems encountered, how you overcame, etc.  The world would love to know!

Regards,

-- John
Reply all
Reply to author
Forward
0 new messages