ginger
ginger copied to clipboard
Investigate delay when adding assets
When building versioned assets (containing a unique hash in their filename), it takes quite a while for Zotonic to pick up the change. This is the case on both on our (Docker) development environment and (native) production ones.
inotify picks up the change quickly, but still the file returns a 404:
lager:set_loglevel(lager_console_backend, debug).
Then execute npm run build
:
zotonic_1 | 12:07:15.181 [debug] [filewatcher] create of "/opt/zotonic/user/sites/abc/lib/elm/dist/style-9fc59629.css"
- Is the problem related to Docker? Docker has some trouble synchronising large amount of files efficiently between the host and the Docker containers.
- Does the problem occur as well when simply adding a static file (
bla.txt
), so without the NPM build step? - Does a
z:flush()
make the files available immediately?
/cc @rl-king
- Not related to Docker, as it happens on our non-Docker servers as well.
- Yes
- No
Does it make a difference if you have mod_development enabled?
Checking if I am correct in understanding the issue.
- Add a new file
- inotify does its work
- Load the file in the browser via
/lib/new/file/path.css
Then step (3) doesn't show the file and returns 404?
Did you try loading the file before step 2? In that case we might have a file handler which is caching the 404.
I just tried:
Lamma:lib marc$ echo `date` > t1.css; curl -I 'http://test.dev:8000/lib/t1.css'
HTTP/1.1 404 Object Not Found
Vary: Accept
Server: MochiWeb/1.1 WebZMachine/2.0 (Z) Zotonic/0.39.0
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Expires: Wed, 10 Dec 2008 14:30:00 GMT
Date: Thu, 24 May 2018 08:04:24 GMT
Content-Type: text/css; charset=utf-8
Content-Length: 26
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Lamma:lib marc$ curl -I 'http://test.dev:8000/lib/t1.css'
HTTP/1.1 200 OK
Server: MochiWeb/1.1 WebZMachine/2.0 (Z) Zotonic/0.39.0
Last-Modified: Thu, 24 May 2018 08:04:24 GMT
Expires: Fri, 24 May 2019 08:04:38 GMT
Date: Thu, 24 May 2018 08:04:38 GMT
Content-Type: text/css; charset=utf-8
Content-Length: 30
Cache-Control: public, max-age=31536000
Access-Control-Allow-Origin: *
So requesting the new file will serve it. What might be an issue is that the file is picked up by re-indexing, if this re-indexing is slow then it will take some time before the file is known to the system.
Iff this is the root cause of the mentioned problem then we could add the file directly to the index of all sites that have enabled the affected module. This is possible iff the file is a new file, as otherwise we need to take the module hierarchy in account (which is done by the indexer).
On a side note, the Zotonic lib
tag is generating hashes based on the modification dates of files. Maybe you can use this tag? Then you also don't need to clean up old files.