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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:57:39+00:00 2026-05-22T19:57:39+00:00

I am have that problem, that I got some javascript that shows a flexibg

  • 0

I am have that problem, that I got some javascript that shows a flexibg image. It only works if it on the bottom of the page. just before

The problem is that the javascript gets loaded as the last. And I can see the flexi bg image just streching wish is not nice.

My code:

<%= javascript_include_tag 'flexibg.js' %>
</body>

What can I do so that the flexi bg javascript get loaded as the first or faster?

EDIT:

I have moved the javascript at the top of my body tag and it still works. But it is slow as hell.

  • 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-22T19:57:39+00:00Added an answer on May 22, 2026 at 7:57 pm

    Ok, to understand your problem you need a basic understanding of how a page loads. The short (not 100% accurate, but good enough) explanation is that the browser goes line by line, starting with the top line of the page. As it hits each script tag, it loads it (and does NOT move on to the rest of the lines until it is done, which is why it is considered best practice to put your script tags at the bottom).

    As soon as the browser has (in its opinion) enough to be worth rendering, it starts rendering what it has. Very likely this is what is causing your problem: the browser is initially loading the image, with the wrong dimensions, and only when the JS gets loaded/run do the correct dimensions get set.

    To solve this problem, what you have to do is hide the entire page initially, and then show it once the page has been loaded. Basically you want to do something to the effect of:

    <script src="yourFile.js"/> <!-- This could go at the end -->
    <body id="theBody" style="display:none"> <!-- rest of document --></body>
    <script>document.getElementById("theBody").style.display = "";</script>
    

    This way, the browser will hit the BODY tag, and subsequent content, but it won’t render any of it because of the display:none style. Then, when the browser gets down to the end, it will hit the script tag that removes the display:none style, showing the page.

    That’s just a quick example, and some details might be off (I don’t think script tags are allowed after the body tag, for instance), but hopefully you get the idea. If not, comment and I’ll try to explain further.

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

Sidebar

Related Questions

I've got here some javascript code, that implements a signature pad. It works fine
I have the problem that an specific step in Ant can only be executed
I've got some (badly written) legacy code that I have to modify but I'm
I've got a c# foreach loop that Is outputting some javascript to initialize some
I have a problem that confuses my users, being that although an item is
I have a problem that I would like have solved via a SQL query.
I have a problem that I feel is best implimented in a stand alone
I have a problem that seems like its a result of a deadlock-situation. Whe
I have encountered a problem that I have not come accross yet when setting
I have a script that constantly segfaults - the problem that I can't solve

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.