ginger icon indicating copy to clipboard operation
ginger copied to clipboard

Investigate delay when adding assets

Open ddeboer opened this issue 7 years ago • 6 comments

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"
  1. Is the problem related to Docker? Docker has some trouble synchronising large amount of files efficiently between the host and the Docker containers.
  2. Does the problem occur as well when simply adding a static file (bla.txt), so without the NPM build step?
  3. Does a z:flush() make the files available immediately?

/cc @rl-king

ddeboer avatar Feb 27 '18 09:02 ddeboer

  1. Not related to Docker, as it happens on our non-Docker servers as well.

ddeboer avatar Mar 12 '18 07:03 ddeboer

  1. Yes
  2. No

rl-king avatar Mar 12 '18 10:03 rl-king

Does it make a difference if you have mod_development enabled?

ddeboer avatar Mar 13 '18 11:03 ddeboer

Checking if I am correct in understanding the issue.

  1. Add a new file
  2. inotify does its work
  3. 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.

mworrell avatar May 24 '18 07:05 mworrell

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).

mworrell avatar May 24 '18 08:05 mworrell

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.

mworrell avatar May 24 '18 08:05 mworrell