Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

404 retrieving javascript asset in dev mode #55

Closed
gschueler opened this issue Jan 15, 2014 · 20 comments
Closed

404 retrieving javascript asset in dev mode #55

gschueler opened this issue Jan 15, 2014 · 20 comments

Comments

@gschueler
Copy link

I'm getting a 404 when retrieving an asset like /assets/knockout.min.js.

If I change its name to "knockout-min.js" then it works fine.

I tried debugging the request and I saw this issue:

I'm not sure why the format is "application/x-javascript". OS/browser: Safari 7.0/OS-X 10.9

Grails: 2.2.4

My config.groovy declares mime type js='application/javascript'

@davydotcom
Copy link
Contributor

ok that needs fixed, in the interum any reason you are requiring knockout js seperately? probably best to have an application.js with

//= require knockout.min.js

//Require your app js

That by chance work at all?

@davydotcom
Copy link
Contributor

Looks like application/x-javascript is an older obsolete equivalent to application/javascript So thats very weird (thanks Safari) :) , Will fix

@gschueler
Copy link
Author

that is how i am doing it. However in dev mode, the knockout.min.js is included as a separate <script> tag and so has its own http request

@gschueler
Copy link
Author

weird, i tested with chrome too, saw the same format application/x-javascript... is it a Mac thing?

@davydotcom
Copy link
Contributor

yea surprisingly this one hasnt hit me yet... Thanks for opening the issue (Im on a Mac as well so kinda odd)

@davydotcom
Copy link
Contributor

Hmm I just attempted to test this. The mime type is determined by using the servletContext.getMimeType(). I just created a testmin.min.js and it was served properly using grails 2.2.1

@davydotcom
Copy link
Contributor

I assume you are running tomcat in dev correct? Also what jdk version are you running

@gschueler
Copy link
Author

I am running Jetty 7.6.0, jdk version 1.7.0_45

@davydotcom
Copy link
Contributor

ah its Jetty then. fantastic.

@davydotcom
Copy link
Contributor

Pushed a release (1.3.0) which should resolve this issue. Asset File definitions can now be defined as multiple accepted content-types.

@davydotcom
Copy link
Contributor

Saw your comment on the commit, whoops! fixed in 1.3.1 wasnt meant to stay.

@gschueler
Copy link
Author

👍 thanky

@gschueler
Copy link
Author

sorry, i still have the same problem with knockout.min.js

since the format is "application/x-javascript", the uri and extension get changed at this line: https://github.com/bertramdev/asset-pipeline/blob/master/grails-app/controllers/asset/pipeline/AssetsController.groovy#L16

the uri becomes "knockout" and the extension becomes "min"

what is the purpose of that if statement? (line 15)

it seems like this code needs to happen before the if statement:

def contentTypes = AssetHelper.assetMimeTypeForURI(request.forwardURI)
format = contentTypes ? contentTypes[0] : null

@gschueler
Copy link
Author

sorry to keep bugging on this issue...i do have a workaround using "-" :)

@davydotcom
Copy link
Contributor

Hah, guess its gonna be one of those days :). its because grails likes to mask off known extensions. i.e. js Hate to ask a silly question, any chance there is a newer jetty version?

@gschueler
Copy link
Author

the extension is correct ("js") prior to the if statement

@gschueler
Copy link
Author

don't worry about fixing this right away :) if I get a chance I'll write up a unit test for it

@davydotcom
Copy link
Contributor

I finally reproduced it by using Jetty, its definitely a Jetty in dev mode issue. I have a few helpers that have been added to AsseHelper since the original writing of this controller, let me clean it up a bit and this may be a non issue now.

@davydotcom davydotcom reopened this Jan 15, 2014
@davydotcom
Copy link
Contributor

Ok, removed the debug println, and built a test app using Jetty and all your versions, finally reproduced the issue and confirmed a fix. Tests are passing for version 1.3.2

@gschueler
Copy link
Author

looks good now thanks a bunch! 🍻

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

No branches or pull requests

2 participants