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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:16:56+00:00 2026-05-28T14:16:56+00:00

I’m currently finishing a huge Backbone.js application with JQuery, RequireJS and Underscore. There are

  • 0

I’m currently finishing a huge Backbone.js application with JQuery, RequireJS and Underscore.

There are many images in my underscore template (lots of .png) and it’s a little bit long to append() || prepend() these templates in my current view.

So there is a good way to do what I do ? I’m looking for a library or an example to do preloading on my templates.

  • 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-28T14:16:56+00:00Added an answer on May 28, 2026 at 2:16 pm

    I don’t think you necessarily need a library for this, unless there’s one specifically for use with templates. As detailed in these related questions, preloading images is relatively simple:

    $("<img />").attr("src", url);
    

    will preload the image at url. It’s pretty obvious that you can apply this easily to an array (here using $.each for concise syntax):

    function preload(urls) {
        $.each(urls, function(i, url) {
            $("<img />").attr("src", url);
        });
    }
    preload(['/images/1.png', '/images/2.png', ... ]);
    

    You don’t need a library for this. The hard part, in your case, is generating the list of URLs to preload. It’s impossible to know the best approach here without understanding your templating system better, but here are a few approaches:

    • If you have your templates available as DOM objects in memory, then you can loop through them using something like $('img').map(function() { return $(this).attr('href') }) to find the URLs. But if you’re using Underscore templates in <script> tags and you don’t make them into DOM objects until you render the view, then this is unlikely to work – it’s going to be a pain and somewhat processor-intensive to render them with dummy data just for the purpose of extracting URLs.

    • If you use a build system like Ant, and if your templates are fairly separate from your other code (e.g. each template in a separate file), then you might consider using regex to parse the templates for URLs and then sticking them into an array in a Javascript file, which you can use for input to your preloader. This is a pretty complicated build task, but it’s probably the best option from a performance standpoint, as all the template parsing happens at build time, not at run time.

    • Another build system approach, probably simpler, would be to put all images you want to preload into a given directory, and then put every file under that directory into the Javascript array. This is probably the easiest approach with Ant, though it might require you to revise your directory structure for images.

    • You can always make your array of URLs by hand, but it will be a pain to keep it up to date with a complex set of templates.

    • If you have a complex app and you want to only preload certain images at any given time, you’ll probably need to identify those images by hand, and then call preload(upcomingImages) at the appropriate time for the appropriate set of images.

    • 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
I want to count how many characters a certain string has in PHP, but
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 am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.