Code Monkey home page Code Monkey logo

Comments (1)

jwhitley avatar jwhitley commented on August 10, 2024

Hi there. Sorry for the delayed response, been down with a cold and playing catch-up. So here's what's going on with require.js itself HTML-wise in your "logged out" case:

<script data-main="/assets/base" src="/assets/require.js"></script>

As I understand it, there are a variety of reasons why it isn't desirable and/or outright breaks if you essentially try to emit another version of the above tag. My offhand sense of what you want to do is more like this:

file setup:
   /assets/common.js     # common code
   /assets/base.js           # your "logged out" base-case
   /assets/logged-in.js

These files would look roughly like this:

// base.js
require(['common'], function (common) {
  // do base stuff
});
// logged-in.js
require(['common'], function (common) {
   // do logged-in stuff
});

Now your layout boilerplate becomes this:

<% if logged_in? %>
  <%= requirejs_include_tag 'logged-in' %>
<% else %>
  <%= requirejs_include_tag 'base' %>
<% end %>

The idea is that your truly common code goes into a module that is picked up by the per-page front-end code. Only one <script> tag for require.js is ever emitted per page this way.

I would also suggest that you hit up the requirejs mailing list and ask around about best practices for per-page setup like this. The above is the "intuitive" solution, but other folks may have ideas and advice that you'll find helpful as well. I'm on the list, so I can help "translate" if needed for any particulars about the gem.

from requirejs-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.