Skip to content
This repository has been archived by the owner on Sep 25, 2021. It is now read-only.

Turbolinks JavaScript object not available in production #15

Closed
aguynamedben opened this issue Oct 8, 2016 · 3 comments
Closed

Turbolinks JavaScript object not available in production #15

aguynamedben opened this issue Oct 8, 2016 · 3 comments

Comments

@aguynamedben
Copy link

When I'm developing, Turbolinks works fine. The Turbolinks JavaScript object is available in my JavaScript console as expected.

development

When I deploy to production, the Turbolinks object isn't defined properly. The Turbolinks object isn't available in the JavaScript console, and my site does full page loads instead of Turbolinks page loads.

production

Upon further inspection of my production environment, the application.js asset is getting compiled and served. jQuery is accessible. Turbolinks appears in the minified JavaScript:

source

My application.js:

//= require jquery
//= require bootstrap
//= require jquery_ujs
//= require turbolinks
//= require_tree .

To me, it seems like Turbolinks is properly setup, but after going through asset compilation for the production environment it's not available in the window for usage.

Gemfile.lock

    turbolinks (5.0.1)
      turbolinks-source (~> 5)
    turbolinks-source (5.0.0)
    uglifier (3.0.2)
      execjs (>= 0.3.0, < 3)

config/environments/production.rb

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier
  # config.assets.css_compressor = :sass

  # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = 'http://assets.example.com'

FWIW I'm deploying on Heroku and relying on them to do asset precompilation, and using the rails_12factor gem. To me it seems like Turbolinks is included correctly in the asset pipeline, but the Turbolinks JavaScript is somehow getting mangled by the precompliation/minification process.

Thanks for all the hard work you put into Turbolinks. My team is extremely excited about it.

–Ben

@sunsheeppoplar
Copy link

Hey @aguynamedben did you ever figure anything out with this issue?

@aguynamedben
Copy link
Author

@sunsheeppoplar I was able to get Turbolinks 5 working on Heroku, but I'm not sure what exactly what got me past this issue. I'm sorry, I know that's not helpful. ☹️ I'm pretty sure it was something with my Rails app, not Heroku. I don't remember reconfiguring Heroku in any special way.

One think you might try is to clear public/assets directory. I've had similarly weird JS issues before when I accidentally compiled assets in public/assets locally and dev was using compiled assets unbeknownst to me.

I'm sorry I can't be more help. Maybe somebody else will find this and understand that the issue is.

@sunsheeppoplar
Copy link

@aguynamedben That's no problem at all. It turned out the reason our Turbolinks object wasn't available was because we had, of course (duh), minified our script. Our problem ended up being something else (that Bootstrap had a dependency, Tether, that wasn't available for some reason). Thanks for responding!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants