Rails respond_to format - .js extension required?
I am capturing link click events and forward开发者_JAVA技巧ing them via ajax, specifically jquery's getScript.
In development everything works fine with regard to respond to format
respond_to do |format|
format.html {
#by default renders show.html.haml
}
format.js {
#by default renders show.js.erb
}
end
This behaviour somehow isn't taking place in production on heroku and the html file is always returned. If I add the file extension and define format recognition to the route then this works ok, however I thought this wasn't necessary?
Thanks in advance.
If anyone comes across this I'll explain what I was doing wrong.
I'm making use of heroku's implementation of varnish to speed up an application. What happens is a previously generated dynamic webpage is downloaded from varnish then javascript calls home to the same url to check for page updates. This improves page response times considerably at the expense of non-js users and search engines potentially viewing slightly stale content.
It appears varnish doesn't distinguish between accepts headers and I was returned the previously cached html. To resolve this I've simply added a time stamp param to the ajax request.
精彩评论