Improving site performance with many images - html

I am currently making a game in HTML/JS that includes approximately 1200 blocks per level. All of the blocks are individual images, but they are a lot of the time similar. They are 20*20 pixels. After inserting the pictures instead of placeholder divs, the perfomance has gone down a lot.
I am not sure, if it is because of the bandwith, but I would expect the pc to cache the images and reuse it.
Or maybe it is a memory problem with the amount of images.
socket.on("sendBlocks",function(blocks,blocksCoords){
if(typeof blocksCoords[area.X + "_" + area.Y] !== "undefined"){
mapLimit.artX = 0;
mapLimit.artY = -1;
while(mapLimit.X + mapLimit.Y != mapLimit.artX + mapLimit.artY){
mapLimit.artY = mapLimit.artY + 1;
if(mapLimit.artY > mapLimit.Y){
mapLimit.artX = mapLimit.artX + 1;
mapLimit.artY = 0;
}
//Change block, executed for every art-coord.
if(typeof blocksCoords[area.X + "_" + area.Y][mapLimit.artX + "_" + mapLimit.artY] !== "undefined"){
switch(blocksCoords[area.X + "_" + area.Y][mapLimit.artX + "_" + mapLimit.artY].type){
case "wood":
$("#" + mapLimit.artX.toString() + "_" + mapLimit.artY.toString()).attr("src","https://db.tt/TyZBx7EG");
break;
case "empty":
$("#" + mapLimit.artX.toString() + "_" + mapLimit.artY.toString()).attr("src","https://db.tt/SdXqMMiE");
break;
}
}else if(typeof blocksCoords[area.X + "_" + area.Y][mapLimit.artX + "_" + mapLimit.artY] === "undefined"){
$("#" + mapLimit.artX.toString() + "_" + mapLimit.artY.toString()).attr("src","https://db.tt/SdXqMMiE");
}
}
}else if(typeof blocksCoords[area.X + "_" + area.Y] === "undefined"){
$(".block").css("background-color","white");
}
This code will be executed every time that the blocks are updated from the server. Checking if the block is wood, empty or undefined. Giving it different textures for each type of block.
The server updates the blocks every 100 ms, is that too fast?
Any suggestions to how this problem can be solved?
Thanks a lot :)

A browser allows a maximum of 6-8 connection to a domain. So say you have 1200 images, it can only download 8 images at a time. This is something I learned recently. The solution to this was to create subdomains like images.website.com. That way the browser will treat the domain as if its a different one and allow you more 6-8 connections. So now 8 connections for website.com and 8 connection for images.website.come. That gives you 16 connections. Its upto you how many subdomains you'd like to make.

Related

Since set-cookie has been deprecated is there a way to STILL make it work (compatibility?)

On an existing web site we have many page using
<meta http-equiv="set-cookie" content="cookiename=value; expires=Fri, 22-Sep-17 08:57:01 GMT; path=/">
Set-cookie has been deprecated in chrome (see below), is there a way to keep compatibility (without change in code) ? At least temporally until correcting every place it's in use...
It seems there is no way to avoid deprecation.
The best on the EXISTING site is to change the meta by a script tag (goal is to minimize change):
REM {update expires date:1 month};
AdjDate := #Adjust(#Now;0;1;0;0;0;0);
Months:="Jan":"Feb":"Mar":"Apr":"May":"Jun":"Jul":"Aug":"Sep":"Oct":"Nov":"Dec";
Days:="Sunday":"Monday":"Tuesday":"Wednesday":"Thursday":"Friday":"Saturday";
Time := #Right("0"+#Text(#Hour(AdjDate));2) + ":" + #Right("0"+#Text(#Minute(AdjDate));2) + ":" + #Right("0"+#Text(#Second(AdjDate));2);
ExpDate := Days[#Weekday(AdjDate)] + ", " + #Right("0"+#Text(#Day(AdjDate));2) + "-" + Months[#Month(AdjDate)] + "-" + #Text(#Year(AdjDate)) + " " + Time + " GMT";
"<script type=\"text/javascript\" id=\"set-cookieJS\">document.cookie = \"" + cookiename + "=" + CartID + "; expires=" + ExpDate + "; path=/\";</script>";
The existing site is in Domino using Formula.

SSRS Hyperlink expressions

I am wanting to understand if possible to set a conditional hyperlink expression in SSRS within the Action setting.
My code which works currently is
=iif(First(Fields!IsHosted.Value, "ReportServer") = "Y", First(Fields!ServerName.Value, "ReportServer"), Globals!ReportServerUrl) +
"/Pages/ReportViewer.aspx?" + Globals!ReportFolder + "/" +
code.GetTargetReportName("Student Performance Against Goal Drill") +
"&GoalCol=" + Code.URLEncode(Parameters!GoalCol.Value) +
"&SectionCol=" + Code.URLEncode(Parameters!SectionCol.Value) +
"&TargetCol=" + Code.URLEncode(Parameters!TargetCol.Value) +
"&ItemCol=" + Cstr(Fields!Item.Value)
I simply want to say "If field B =0 then do nothing, else use the above. I am not familiar how to wrap this statement in the action.
You can nest IIF() functions:
=IIF(First(Fields!B.Value,"ReportServer") = 0,Nothing,
iif(First(Fields!IsHosted.Value, "ReportServer") = "Y",First(Fields!ServerName.Value, "ReportServer"), Globals!ReportServerUrl) +
"/Pages/ReportViewer.aspx?" + Globals!ReportFolder + "/" +
code.GetTargetReportName("Student Performance Against Goal Drill") +
"&GoalCol=" + Code.URLEncode(Parameters!GoalCol.Value) +
"&SectionCol=" + Code.URLEncode(Parameters!SectionCol.Value) +
"&TargetCol=" + Code.URLEncode(Parameters!TargetCol.Value) +
"&ItemCol=" + Cstr(Fields!Item.Value)
)
I don't know what the dataset structure is but this could help you.

Actionscript - call symbol using variable as part of name (increment number) and change x/y position

Looked everywhere for this but can't find anything so I hope someone can help. Maybe there is something online but I am not putting it in the right words....
Using Actionscript I want to change the x and y multiple symbols I have that go up by row number and col number in their names i.e. SP_01_01 - SP_01-10...... SP_02_01... etc
I need to access that symbol using two other variables holding the Number parts of the name and change the x and y values.
Here is what I have tried from what I've searched and thought was corrent
["SP__" + rownum + "_" + colnum].x = xcol;
["SP__" + rownum + "_" + colnum].y = yrow;
Try to call objects in this way:
getChildByName("SP__" + rownum + "_" + colnum).x = xcol;
getChildByName("SP__" + rownum + "_" + colnum).y = yrow;
This way even better:
import flash.display.DisplayObject;
var cell:DisplayObject = getChildByName("SP__" + rownum + "_" + colnum);
cell.x = xcol;
cell.y = yrow;

How to deal with information received in two packets

This is the case. I want to make a game, client being made in flash and server on java. From server side, the first byte i write on the stream is the protocol id, like this:
try
{
Output.writeByte(LOGIN);
Output.writeByte((byte)ID);
Output.writeByte(new_position.x);
Output.writeByte(new_position.y);
Output.flush();
}
After the 'onResponse' event is triggered, the socket is read like this:
type:int = socket_client.readByte();
if (type == 0x1)
FP.console.log("You are logged as " + socket_client.readByte() + " in x:" + socket_client.readByte() + " y:" + socket_client.readByte() );
else if (type == 0x2)
FP.console.log("You are now in x:" + socket_client.readByte() + " y:" + socket_client.readByte());
As you probably have guessed by now, this gives me some problems. Sometimes, server sends the information split in two, so the above code throws an EOF exception. Tracing the following code gives me sometimes this result:
trace("SIZE: " + socket_client.bytesAvailable);
//var type:int = socket_client.readByte();
var values:String = "";
while (socket_client.bytesAvailable > 0)
values += socket_client.readByte() + " ";
trace(values);`
Values:
SIZE: 1
2
SIZE: 2
2 6
The first '2' is the protocol id, the second and the third stands for x and y values.
Now, the question is, how can i prevent this to happen? How could i 'wait' until i have all the information needed?
Btw, on java this never happens, but i have no more control than on as3.
Add BufferedOutputStream in output initialization like this:
Output = new DataOutputStream(new BufferedOutputStream(connection.getOutputStream()));
Basically you need to switch your message format from [type, data] to [type, length, data]. Then, wait to process the data until bytesAvailable >= length, otherwise put it into a buffer.
Here is an example SOCKET_DATA handler that uses this logic:
https://github.com/magicalhobo/Flash-CS5-mobile-proxy/blob/master/com/magicalhobo/mobile/proxy/MobileClient.as#L110

Basic boolean minimization

I am trying to simplify the following piece of boolean algebra so I can construct the circuit :
A'.B'.C.D + A'.B.C.D' + A'.B.C.D + A.B'.C'.D + A.B'.C.D + A.B.C'.D + A.B.C.D' + A.B.C.D
So far I have gotten it to :
(C.D) + (B.C) + (A.C'.D)
Is this correct?
I want to get the best possible minimization.
The steps I have went through so far are :
A'.B'.C.D + A'.B.C.D' + A'.B.C.D + A+B'+C'+D + A.B'+C+D + A.B.C'.D + A.B.C.D' + A.B.C.D
= A.A'(B'.C.D) + A.A'(B.C.D') + A.A'(B.C.D) + B.B'(A.C'.D)
= (B.C.D) + (B'.C.D) + (B.C.D) + (B.C.D') + (A.C'.D)
= (C.D) + (B.C) + (A.C'.D)
Can I do any more?
Assuming your equation is actually:
X = (A'.B'.C.D) + (A'.B.C.D') + (A'.B.C.D) + (A+B'+C'+D) + (A.B'+C+D) + (A.B.C'.D) + (A.B.C.D') + (A.B.C.D);
I just ran this through Logic Friday and it factored it down to:
X = 1;
So you might want to check your simplification work and/or check that you've given the correct equation.
However I suspect there may be typos in the original equation above, and perhaps it should be:
X = (A'.B'.C.D) + (A'.B.C.D') + (A'.B.C.D) + (A.B'.C'.D) + (A.B'.C.D) + (A.B.C'.D) + (A.B.C.D') + (A.B.C.D);
?
In which case Logic Friday simplifies it to:
X = B.C + A.D + C.D;
The only thing I can see that you could possibly do is distribute the "C" in the left two terms:
(C).(B+D)+(A.C'.D)
Or you could distribute the "D":
(C+A.C').D + (B.C)
Response to Comment: The distributive law is described here: http://www.ee.surrey.ac.uk/Projects/Labview/boolalgebra/. See the information under heading "T3"
Here's another solution (found by brute force):
(a+c).(b+d).(c+d)
for simplifying boolean expressions use karnaugh maps. i think it is very much useful if we less number of variables. but if we have more variables then we can follow methods because this method is not that preferable.