Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7702589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:15:40+00:00 2026-05-31T23:15:40+00:00

I’m writing a mountable Rails 3.1 engine that adds features to the main app

  • 0

I’m writing a mountable Rails 3.1 engine that adds features to the main app (i.e. it isn’t isolated). The engine’s JS depends on jQuery, jQueryUI, DataTables and JSTree (among other libraries) so the engine’s manifest looks a little something like:

// my_engine.js

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require jstree_pre1.0_fix_1/jquery.jstree.js
//= require_tree .

I can then conditionally load this file into the main app’s layout using:

<%= javascript_include_tag 'application' %>
<%= javascript_include_tag 'my_engine/my_engine' if user_logged_in? %>

However, if the main app’s manifest already includes one of the dependencies (most likely jQuery and jQuery_UJS) then those dependencies will be loaded twice. I’ll see something like:

<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
...
<script src="/assets/application.js?body=1" type="text/javascript"></script>

<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-ui.js?body=1" type="text/javascript"></script>
<script src="/assets/jstree_pre1.0_fix_1/jquery.jstree.js?body=1" type="text/javascript"></script>
...
<script src="/assets/cms/application.js?body=1" type="text/javascript"></script>

Sprocket‘s require directive will only require an asset once within the same bundle but here I am working with two bundles. To make it simple for other devs implementing my engine, I’d like them to be able to include one line that detects whether or not the shared dependencies are already included. Is there are nice way of doing this using Sprockets?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T23:15:41+00:00Added an answer on May 31, 2026 at 11:15 pm

    In the end, I chose to not to make the vendor libraries hard dependencies and I’ve written into the documentation that they must be required manually. This creates a little bit more work for downstream developers but I think it offers the most flexibility.

    So, the engine’s manifest file, my_engine.js, is now just:

    //= require_tree .
    

    and an example main app:

    application.js:

    //= require jquery
    //= require jquery_ujs
    //= require_tree .
    

    my_engine_requirements.js:

    //= require jquery-ui
    //= require jstree_pre1.0_fix_1/jquery.jstree.js
    //= require my_engine/my_engine
    

    application.html.erb:

    <%= javascript_include_tag 'application' %>
    <%= javascript_include_tag 'my_engine_requirements' if user_logged_in? %>
    

    This solution technically doesn’t answer my original question but it’s what I did after rationalising the situation a bit more.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.