Is removing unused loaded images good practice?

Is it good practice to remove images that were preloaded but never used? Here is what I have in the Create function just in case:

		for (var x = 0; x < xArray.length; x++) {		
			
			if(myCode == xArray[x]){

		    		var myConfig = {
					key: myCode,
        				x: 0,
		        		y: 0
    				};

				this.make.image(myConfig).setOrigin(0);

			}
			else
			{

				/*
		    		var myConfigRemove = {
					key: myCode,
        				x: 0,
		        		y: 0
    				};

				this.textures.remove(myConfigRemove) 
				*/

			}

		} 

It would be better not to load them in the first place.

I think what I’ll do then is create multiple game.js files for each unique background image and then choose the game.js file I will use in the html file.

You could just use a switch and load a different image in every case, and not loading any on default or something like that, depending on the conditions you want.

1 Like