[GUIDE] Reduce HTML weight/length from the server core.

Salty Mike

hella salty
VIP
Неукротимое пламя
Сообщения
348
Розыгрыши
0
Решения
4
Репутация
163
Реакции
134
Баллы
1 438
Хроники
  1. Chronicle 4: Scions of Destiny
  2. Interlude
  3. Chaotic Throne: High Five
  4. Grand Cursade
  5. Salvation
  6. Fafurion
Исходники
Присутствуют
Сборка
Mobius
I realise that this is posted in the wrong section, but I could not post it in the guides section. I would kindly ask the administration to move it to the appropriate section and remove this sentence.


Greetings, folks!

Today I'll present to you a way to optimise the HTML length by up to 30%, depending on the nesting. The examples I give are taken from an old Interlude core, but the general idea is applicable to all java-based cores.

Proof of concept: The two important bits are the (1) Original HTML size row and the (4) No Tabs/Rows size row, which represent the before and after, respectively.
1699347725858.png

STEPS:
1. locate the `setHtml(String text)` method inside `NpcHtmlMessage.java`.

2. add the following bit of code as a standalone method:
Java:
    /**
     * Replaces all occurrences of New Rows and Tab spaces in the string.
     * @param text the string that may contain invalid characters
     * @return the string with invalid characters removed
     */
    public static String removeTabSpacesAndNewRows(String text)
    {
        return text.replaceAll("[\\t\\n]", "");
    }

3. find the last ocurence of the `text` String variable in the `setHtml()` method, and push it through this newly created method like so: `removeTabSpacesAndNewRows(text);`.

4. example of the final result.
1699347679701.png

5. You could further refine it by processing the `text` variable between the two IF clauses by creating a new local variable, assigning it a value of `text` and then replacing the subsequent `text` mentions in the `setHtml()` method with this new local var. Here's what it could look like:

1699347857857.png
UPDATE:
(thanks to @xdem for pointing it out)

You can instead apply the same logic/method to the HTMCache.java.
To do so, locate the loadFile() method and recycle the String/Text/Content through the removeTabSpacesAndNewRows() method, or just forget about the method and just copy its functionality and apply it in the loadFile() method.

KEEP IN MIND that if you will us the removeTabSpacesAndNewRows() method, it should be best if you moved it to another java class, preferrably in some UTILITY class.

Here is an example implementation:

1699398797174.png
 
Последнее редактирование:
I realise that this is posted in the wrong section, but I could not post it in the guides section. I would kindly ask the administration to move it to the appropriate section and remove this sentence.


Greetings, folks!

Today I'll present to you a way to optimise the HTML length by up to 30%, depending on the nesting. The examples I give are taken from an old Mobius core, but the general idea is applicable to all java-based cores.

Proof of concept: The two important bits are the (1) Original HTML size row and the (4) No Tabs/Rows size row, which represent the before and after, respectively.
Посмотреть вложение 55946

STEPS:
1. locate the `setHtml(String text)` method inside `NpcHtmlMessage.java`.

2. add the following bit of code as a standalone method:
Java:
    /**
     * Replaces all occurrences of New Rows and Tab spaces in the string.
     * @param text the string that may contain invalid characters
     * @return the string with invalid characters removed
     */
    public static String removeTabSpacesAndNewRows(String text)
    {
        return text.replaceAll("[\\t\\n]", "");
    }

3. find the last ocurence of the `text` String variable in the `setHtml()` method, and push it through this newly created method like so: `removeTabSpacesAndNewRows(text);`.

4. example of the final result.
Посмотреть вложение 55945

5. You could further refine it by processing the `text` variable between the two IF clauses by creating a new local variable, assigning it a value of `text` and then replacing the subsequent `text` mentions in the `setHtml()` method with this new local var. Here's what it could look like:

Посмотреть вложение 55947
you can go further and write regular expression for remove comment strings if it exist.
 
you can go further and write regular expression for remove comment strings if it exist.
The last time I checked, the comments were not being parsed. I'll test again and update my post if necessary.

Yes, I can confirm that html comments (<!-- -->) are not being parsed from the server to the client.
As evident from the two screenshots. The screen with the system message is before and after deleting a huge comment block from the same HTML.

1699349081788.png

1699349189661.png
 
Назад
Сверху Снизу