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

  • Home
  • SEARCH
  • 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 374617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:25:23+00:00 2026-05-12T14:25:23+00:00

I’m running a fairly large web application which contains an increasing amount of JQuery

  • 0

I’m running a fairly large web application which contains an increasing amount of JQuery code for both UI polish and making AJAX requests.

Larger chunks of code live in their own, dedicated .js file, but there are an increasing number of pages (primarily forms) which use a small sprinkling of JQuery for showing/hiding form elements, modifying classes etc. Presently I put this code in the $(document).ready() block in my main application.js file.

Given this, on any given page view application.js is loaded and all the JQuery code in this ready() block is executed despite the fact that only one or two calls will be relevant to the current page. Are there any performance implications of doing this or is it actually quite negligible? If there are performance implications, what is the recommended alternative way of managing these page-specific JQuery (or indeed any type of Javascript) snippets in large Rails apps?

Despite being considered bad-practice, wouldn’t it make more sense to define simply JQuery rules which are specific only to a single form inside the form partial itself?

  • 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-12T14:25:23+00:00Added an answer on May 12, 2026 at 2:25 pm

    The advantage of having everything in one file (application.js) is that the client will have cached this file, and it will serve them locally on consequent HTTP requests.

    The performance hit you may get is related to your jQuery code itself. Specifically, on searching DOM elements that you later act on. Sizzle, the new selector engine in jQuery 1.3, parses your selectors from right-to-left, just like browsers parse CSS. Therefore it’s best to try to narrow down your selection as much as possible on the right of the selector query. jQuery itself is optimized for #id selectors too (skips going through Sizzle), which is good to have in mind. For this reason, doing $(‘#id’).find(‘div’) is much faster than doing $(‘#id div’). Other than that, most warnings that apply to google page speed regarding CSS selectors will apply to your jQuery selectors.

    Regarding page specific js, here’s one way to do it:

    Add a <%= yield :javascripts %> on your layout, right before your closing body tag. Then you can add this to your view, after your html:

    <% content_for :javascripts do %>
      <% javascript_tag do %>
        //your js here
      <% end %>
    <% end %>
    

    This saves an HTTP request and keeps your view behavior close to your view which is a win, although it doesn’t minify your javascript. That is a compromise that has worked well for me.

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

Sidebar

Related Questions

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 am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
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 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
I have this code to decode numeric html entities to the UTF8 equivalent character.
I would like to run a str_replace or preg_replace which looks for certain words

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.