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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:05:23+00:00 2026-06-03T06:05:23+00:00

I am building an asset loader for a simple Object-Oriented game engine in HTML5.

  • 0

I am building an asset loader for a simple Object-Oriented game engine in HTML5. Right now I know of two ways to make the asset loader (summarized below) and I prefer the second approach. My question is, is the second way guaranteed to always work for all browsers?

For clarity:

  • the name of the class in question is AssetLoader,
  • the method to load all assets is called loadAssets(),
  • the main class is Game,
  • and the main game loop is runGameloop().

Approach 1

Create an instance of AssetLoader that will persist throughout the entire game. When loadAssets() is called at game start, it will create a dictionary that will hold key/value pairs of all the assets for the duration of playtime.

When a sprite requires an image, it will query AssetLoader with a given name (ex. “Archer”), and the instance will return the appropriate image for the sprite to use.

Approach 2

Create an instance of AssetLoader that will not persist throughout the game (it will be called once and not be assigned to any instance variables).

The instance’s responsibility will be to query the server for each asset which will cause the browser to cache the assets; much like:

function AssetLoader()
{

    ...

    self.loadAssets = function(runGameloop)
    {
        self.tempImage = new Image();

        $(self.tempImage).load(function()
        {
            self.assetsLoadedSoFar += 1;
            if(self.assetsLoadedSoFar === self.totalAssets)
            {
                self.runGameloop();
            }
        });

        self.tempImage.src = "assets/sprites/archer/archerSpriteSheet.png";
    }

    ...

}

Now whenever a sprite needs an image, that image should now be cached in the browser and it just loads it with a new Image() object without going through AssetLoader.

Why I prefer approach 2

1.) I want to avoid introducing unnecessary layers of abstraction to the engine, I don’t want to have to go through AssetLoader everytime I want to load an asset.

2.) If I have alot of assets in the game, I don’t want them all to be simultaneously loaded in a single instance of AssetLoader. Perhaps someone can correct me but wouldn’t having all those resources loaded at once unnecessarily strain the game?

So right now I have a working version of Approach 2 here and am mostly happy with it but what I need to know is: “is the browser guaranteed to always cache a given image using approach two?” or is that something I can’t rely on? Are there certain configurations in which automatic caching might be turned off? (is that even possible?). Do you have any other approaches you think are better? Thanks alot for your time!

  • 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-06-03T06:05:24+00:00Added an answer on June 3, 2026 at 6:05 am

    I don’t think you can rely on the browser cache. It is possible to disable automatic caching and I imagine it is reasonably common for people to do just that.

    I’ve done exactly this in the past for two reasons:

    1. Low disk space on a computer shared by the family (multiple separate accounts)
    2. When developing, in order to ensure that the latest changes are always visible on page refresh

    Also, caching is disabled in incognito / private browsing modes of Chrome / Firefox.

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

Sidebar

Related Questions

So here's the deal, I am building out a site right now and want
I have a simple game that I am building in as3/air using flash develop,
Building on another SO question , how can one check whether two well-formed XML
I building a simple (crude, in fact) gallery in html / twig, css and
I'm building a JAX-RS web service (Jersey) and now I'm trying to start using
Outline I'm building a form for a specific page, where users can make suggestions
For a system I am currently building, the following two scenarios occur: My permissions
I know that I shouldn't be building a new associated image for my gallery
Client is building a web based Digital Asset Management system. Here is the scenario:
I'm using pure C++ in my engine to create a game engine in android.

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.