⬆️ ⬇️

Enchanting architectural approaches or Javascript is our everything

My kung fu is stronger, Vasya said and continued to write on a wonderful site.





Once there was one great developer, for simplicity we call him Vasya. Vasya was fine, he was the head of the IT department and wrote a large portal on which the authorities had high hopes.



Vasya laid wonderful architecture in his portal.

')

The admin panel is the same for the convenience of users. It was written on WinForms. Let not all users suspect that in this panel they will have to edit the Java Script in their hands in some places, but this is nothing, you can survive. Everything rustles, everything works, the database is briskly filled with a tree of pieces of text interspersed with javascript, everyone is happy. The client side is another matter. So you have to do so that it can be viewed through the browser. Vasya understood that there are a lot of requests in highly loaded query systems, and the static page loads very quickly. Therefore, we will give the user a static page, it does not matter that it is one, but fast. He didn’t want a regular website, because “through the classic approach to development it’s impossible to create a fast website, it will always be flooded with iron on performance” (C). Therefore, he went another way, transferring logic to the client’s side is our everything, he created a piece of JS code weighing a couple of hundred kilobytes, the functions of which include loading through server handlers those pieces of code in javascript that are in the database with content, processing to pressing menu items, etc. Because Since javascript works on the client side, then by and large, what the writing is there, so the entire html DOM generation takes place on the javascript, not quite true, but what is inside the body. But you can not worry about server-side code optimization, optimized sql queries, etc., we transfer the load to the client.



Also in the development process there are nontrivial tasks, such as getting the exchange rate, weather, etc. These tasks are solved easily and quickly, a new handler is created which requests the page every minute, the headdog in turn requests the home page of the central bank from which we pull out courses and send data to JS so that they can register themselves on the page immediately. Because modularity is cool, then the weather has its own handler and its call every minute. Localization on the desired language is done correctly in the database, but the truth is only 30%, for the convenience we spread the content evenly in JavaScript and Code-Behind, this is all done wonderfully with the help of a switch.





Selected pieces of code:



Generation of markup html pages: (and approximately 5-6 code pages)

document.body.style.margin = "0px";

document.title = sTitle;

document.body.style.backgroundColor = sColor0;

document.body.style.backgroundImage = "url(" + sImgUrl0 + ")";

document.body.style.backgroundRepeat = "repeat-x";

tableMain = document.body.appendChild(document.createElement("table"));

tableMain.style.fontFamily = "serif";

tableMain.style.fontSize = "10.5pt";

tableMain.style.fontWeight = "bold";

tableMain.id = "tableMain";

tableMain.style.width = "100%";

tableMain.style.borderCollapse = "collapse";

tableMain.cellPadding = "0px";





Data in the database:

⌠var var oCell; // . var divAny; ⌡var ⌠ini oCell = document.getElementById("cellInfo"); ⌡ini ⌠one ₢₢₢InfoClear(); ⌡one // 0 ₢₢₢A2Add(oCell,"∃∃∃"); oCell.appendChild(document.createTextNode("\u00A0\u00A0\u00A0")); // 1 ₢₢₢A2Add(oCell,"∃∃∃"); oCell.appendChild(document.createTextNode("\u00A0\u00A0\u00A0")); // 2 ₢₢₢A2Add(oCell,"∃∃∃","1_2_76_22"); oCell.appendChild(document.createTextNode("\u00A0\u00A0\u00A0")); // 3 ₢₢₢A2Add(oCell,"∃∃∃"); ₢₢₢BrAdd(oCell); ₢₢₢BrAdd(oCell); // 4 ₢₢₢TextAddDivBlack(oCell,"∃∃∃",1); ₢₢₢BrAdd(oCell); divAny=₢₢₢div6Add(oCell); // 5 ₢₢₢TextAdd(divAny,"∃∃∃"); ₢₢₢TextAdd(divAny,"www.bolshoybiznes.ru"); // 6 ₢₢₢TextAdd(divAny,"∃∃∃"); // 7 ₢₢₢TextAddBrDivGray(oCell,"∃∃∃"); // 8 ₢₢₢TextAddDivGray(oCell,"∃∃∃"); // 9 ₢₢₢TextAddBrDivBlack(oCell,"∃∃∃"); // 10 ₢₢₢TextAddBrDivBlack(oCell,"∃∃∃"); // 11 ₢₢₢TextAddBrDivBlack(oCell,"∃∃∃"); // 12 ₢₢₢TextAddBrDivBlack(oCell,"∃∃∃"); // 13 ₢₢₢TextAddBrDivBlack(oCell,"∃∃∃"); ₢₢₢BrAdd(oCell); // 13+4=17 divAny=₢₢₢divList6Add(oCell,["∃∃∃","∃∃∃","∃∃∃","∃∃∃"]);





Getting currency rates:

sAnswer = System.Text.Encoding.UTF8.GetString(oWebClient.DownloadData("http://cbr.ru/"))

tDate1 = oRegExInDate1.Match(oRegExDate1.Match(sAnswer).Value).Value

tDate2 = oRegExInDate2.Match(oRegExDate2.Match(sAnswer).Value).Value

dD1 = oRegExInD1.Match(oRegExD1.Match(sAnswer).Value).Value

dD2 = oRegExInD2.Match(oRegExD2.Match(sAnswer).Value).Value

dE1 = oRegExInE1.Match(oRegExE1.Match(sAnswer).Value).Value

dE2 = oRegExInE2.Match(oRegExE2.Match(sAnswer).Value).Value





Why did I write all this? Yes, just so boiling.

What is the saddest thing: the attempts to help are perceived with hostility and everything is as it is. Some people are satisfied, others understand what will happen next in terms of refinement, support, etc., but it's still there.

Source: https://habr.com/ru/post/81235/



All Articles