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 6951693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:15:09+00:00 2026-05-27T14:15:09+00:00

I would like to somehow prevent certain assets from being included in the asset

  • 0

I would like to somehow prevent certain assets from being included in the asset pipeline in the development environment.

So far, I have tried the following:

# app/assets/javascripts/application.js.erb
<% if Rails.env.production? %>
//= require google_analytics_snippet
<% end %>

and

# app/assets/javascripts/application.js.erb    
<% if ENV['RACK_ENV'] == 'production' %>
//= require google_analytics_snippet
<% end %>

All I seem to be achieving is whether or not the //= require google_analytics_snippet line appears in the manifest. The actual code in the google_analytics_snippet.js file is never loaded, regardless of environment when I use either of these attempted solutions.

Is there a way I can do this?

Edit:
I was using a javascript file called olark.js in my examples when I first posted this question. That was a bad choice of example since Olark has a rubygem which may solve the problem. I have changed the example because I am looking for the general form solution.

  • 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-27T14:15:09+00:00Added an answer on May 27, 2026 at 2:15 pm

    I’ve looked through the source of the sprockets and I found,
    that the directive preprocessor always runs before any engine.
    So, it’s not possible to add any conditional logic into the directives section with ERB or other engine.

    • https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/environment.rb#L51
    • https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/processing.rb#L36
    • https://github.com/sstephenson/sprockets/blob/master/lib/sprockets/context.rb#L174

    UPDATE

    Joshua Peek, answered on my question:

    The answer is yes, but if this is what you are trying to do:

    <% if Rails.env.production? %> 
    //= require google_analytics_snippet
    <% end %>
    

    try this instead:

    <% if Rails.env.production?
    require_asset "google_analytics_snippet"
    end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a static method in my code that I would like somehow to
I have some hidden inputs like this <input name=exam.normals[1].blahblah ..../> I would like somehow
I would like to prevent my clients from instantiating entities through the constructor. As
My question is a NodeJS newbie question. I would like to somehow detect if
I would like to avoid the if statement below. Can I somehow copy the
Using a Google Chrome Extension, I would like to fire some event or somehow
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
I would like to access the values in the ConfigurationManager.AppSettings object from a MEF
I have a situation where I would like to present a list of the
I have a macro that I would only like to be called at file

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.