-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/translations.js slows down Searx. #2064
Description
This commit 4ca0d8c adds a new URL to serve a non static javascript file.
The script is loaded in the <head> section of the HTML page: https://github.com/asciimoo/searx/blob/4ca0d8cb0fd6c0e6b1301a6e8577aea6d928e9dc/searx/templates/oscar/base.html#L13
It takes usually at least 100ms to download (5% of 2 seconds), sometimes more, and since it is in the <head> section, the browser waits until the URL is downloaded and the content parsed. The file is reloaded each time since the user can change the locale.
You can see that in the devtools of a browser, or using curl:
curl --write-out "%{http_code},%{time_total},%{time_connect},%{time_appconnect},%{time_starttransfer}\n" --silent --output /dev/null "https://searx.be/translations.js"
It slows down Searx page load.
solution 1: remove translations.js
- remove
translations.js - add an additional attribute
data-could-not-loadto thescriptelement:
https://github.com/asciimoo/searx/blob/4ca0d8cb0fd6c0e6b1301a6e8577aea6d928e9dc/searx/templates/oscar/base.html#L101-L103 - load the value from this file:
https://github.com/asciimoo/searx/blob/4ca0d8cb0fd6c0e6b1301a6e8577aea6d928e9dc/searx/static/themes/oscar/js/searx_src/01_init.js#L26-L29
This solution is good for now because there is only one string to translate (in the oscar theme).
If there are more than one translation, a JSON structure can be serialized:
<script src="searx.min.js" ... data-i18n="{ 'could_not_load': 'could not load data!' }" />Side note: the simple theme already does something similar (see no_item_found):
- https://github.com/asciimoo/searx/blob/c41db5f1ba9984a916261535a9227fadb897f4bf/searx/static/themes/simple/js/searx_head/00_init.js#L28-L36
- https://github.com/asciimoo/searx/blob/c41db5f1ba9984a916261535a9227fadb897f4bf/searx/templates/simple/base.html#L23-L29
solution 2: translations.<:locale>.js
Instead of one dynamic file, there is one per locale. The HTTP headers make sure the browser keeps the files in the cache.
This solution leak the user locale in the reverse proxy logs.