igrigorik / closure-sprockets

Sprockets processor for Google's Closure tools
http://www.igvita.com/2011/08/16/rails-3-asset-pipeline-google-closure/
54 stars 11 forks source link

Routing error on deps.js #2

Closed joshjhall closed 13 years ago

joshjhall commented 13 years ago

Just trying to set this up on a fairly new project to play with closure.

I'm getting the following routing error... ActionController::RoutingError (No route matches [GET] "/deps.js")

Looking at the source, the following line is being put into the head after my first call to goog.require()...

I assume this should be routed to something like src="assets/deps.js"; however, I'm not sure what the "right" approach is for this with the asset pipeline and vendor dir.

igrigorik commented 13 years ago

Hmm, actually we shouldn't even need that. I'm still learning closure myself, but from my understanding deps.js is used for dynamic loading use cases - it basically specifies the dependency tree. This is something the asset pipeline should handle on the server side for us, hence the file is not needed.

Now to figure out how to disable it.. :-)

joshjhall commented 13 years ago

After a bit of experimentation I found that turning on debug mode for sprockets will cause things to hang. So... config.assets.debug = true

Leads to things hanging at... Started GET "/assets/goog/deps.js" for 127.0.0.1 at 2011-09-28 02:18:29 -0500 Served asset /goog/deps.js - 304 Not Modified (2ms)

Not sure if that'll help, but it's the only thing I found that might be useful.

igrigorik commented 13 years ago

Reading through the docs, looks like there are several ways to disable this, one of which is by adding this prior to loading closure files:

<script type="text/javascript">
  var CLOSURE_NO_DEPS = true;
</script>

Should also be able to bake this directly into the pipeline to avoid the extra hassle.

joshjhall commented 13 years ago

Hmm... well, I no longer get a 404 error, but it's not actually loading the closure files at all.

I have this in the head of my template (using HAML here)

%script{ :type => "text/javascript" }
  var CLOSURE_NO_DEPS = true;
= javascript_include_tag :application

And this in my application.js

goog.require('goog.dom');
newHeader = goog.dom.createDom('h1', {}, 'Hello world!');
goog.dom.appendChild(document.body, newHeader);

I'm getting a "Uncaught TypeError: Cannot call method 'appendChild' of null" error, because goog.dom isn't being included correctly.

igrigorik commented 13 years ago

Hi Josh, please take a look at this thread: https://github.com/igrigorik/closure-sprockets/issues/1

Closing this thread, since it's the same issue.

dogenpunk commented 12 years ago

I was just having this very same issue and, like @joshjhall I thought it was an issue with the loading of 'goog.dom'. After adding the var CLOSURE_NO_DEPS = true; I was getting the "Uncaught TypeError" he mentioned. I resolved it by changing the code from the README

goog.require('goog.dom');

function sayHi() {
    newHeader = goog.dom.createDom('h1', {}, 'Hello, world!');
    goog.dom.appendChild(document.body, newHeader);
}

window.onload = sayHi;

In the closure library goog.dom.appendChild is defined

goog.dom.appendChild = function(parent, child) {
  parent.appendChild(child);
};

The issue is actually trying to call document.body before the DOM is loaded.