[SOLVED] Are static files updated when not changed?

I am building a medical education department site which will publish weekly blog post - each with 3 or 4 PDFs linked as static files (mainly slides and teaching evaluation reports). With time therefore the number of static files attached to the blog posts will grow.

Mechanism of publishing is via rsync or ftp.

My question: when I run hugo does it update static files in any way?

I would like to upload just the new static files and keep the previous ones in place, unless changed. I am afraid that every time hugo and upload script are run this may cause to re-upload past static files.

I am not a professional websit site developer or programmer - I am one of the teachers who is also a hugo enthusiast and I need to formulate some simple method for keeping up the site for others who will also publish, therefore I need to find out bets practice as to how to deal with larger number of static files attached to blog posts.

Thank you for your insights.

No… Hugo does not change static files.

I had sync problems with my server too.
My way ist to sync the Hugo source folder and build the side on the server.

As @alexandros said: No. But perhaps you meant if Hugo server is updating the static directory during his run if you add/remove files. Answer: Yes.

1 Like

In case a follow-up question is, can I only update pages that have changed, then yes, you can. You can see how I use rsync at Making a website: KISS my deployment goodbye - Webcraft - talkgroup. My deployment script is currently three lines:

tmpwatch -m -v 24 /tmp/hugo_cache/
hugo
rsync -uavh public/ interi:interi.org/

That only uploads files that have changed, but also other stuff, so just check your rsync parameters to make sure you are doing exactly what you want. For instance, I believe my parameters remove items not found in public, which may not be what you want. :slight_smile:

1 Like

Hello,

Thank you very much for your help. So far I think the case likely is that hugo upon compilation copies files and directories from /static directory into /public and it is /public directory content that gets deployed. So if hugo copies (overwriting) the files in ‘public’ every compilation time, then rsync would think that the files have been updated, because timestamp would be different (newer). In which case the whole content coming from /static directory would be uploaded every time the site is changed.

My update line is:

hugo && rsync -avz --delete --exclude lime public/ user@host.machine.org:/var/srv/http/public_html/

Which deletes files on server that are not in my local /public directory with exception of directory ‘/lime’ containing a limesurvey installation.

If I add -u flag it would only skip files that are newer on the destination, but if hugo just copies static files/dirs into /public then they always would have newer timestamp than on the server and as I have said would have to be transferred every time, which in time would generate a significant overhead.

Is there any way how to avoid this problem of re-uploading static files when hugo is run locally, or am I overthinking this and/or hugo already has some clever mechanism that takes care of this potential problem?

http://interi.org would not have this problem because it appears a very small site without many static files.

Thanks again for your insights.

The important part here is to use --checksum flag on rsync.

For self promotion, if you deploy to Amazon S3, using a tool like GitHub - bep/s3deploy: A simple tool to deploy static websites to Amazon S3 and CloudFront with Gzip and custom headers support (e.g. "Cache-Control") will also handle the syncing properly, i.e. not upload unchanged files.

Thank you Bjørn,

Good to know that this is what would solve the problem. I will use that. As in the future I will have to leave the site to be updated by less technophilic people I am wondering if there is also a way around this problem when using ftp.

I would be totally for using s3deploy but I am in health service context and our IT would insist in using their intranet web server, which, I think, would exclude S3 or any other cloud service.

@r0berts FTP is generally slower than rsync. Giving them a batch file to run might be one way to make rsync really easy, compared to exposing them to FTP. Personally, I either use Bep’s s3deploy for S3 or, put my rsync command in a zsh function. If your users are on Windows though, having them double click a batch file is pretty easy.

If you’re also incorporating git, you might also consider, a CI solution like CircleCI, provided the intranet server has an ssh endpoint you can access from the Internet. That way, your publishing happens when you commit to git. You’d need to set up the CircleCI script to do the rsync.

1 Like

Thank you guys, I will be OK with this. Holding my breath as my IT are very windows orientated, but I will post here once I get a final solution.

maiki, could I ask you out of interest why you run tmpwatch for the last 24 hours not modified files in root/tmp directory hugo cache dir? My understanding is that it probably has no relevance to hugo publishing and everything under /tmp gets cleared at next reboot or earlier anyway, if I am getting it right.

I’m not sure what to tell ya. I rarely reboot my laptop, but need to update data up to once a day. If I didn’t clear the Hugo cache, I wouldn’t ever refresh that data except after a reboot.

If you are wondering about the specific number of hours, that is as fast as I go. I practice slow webcraft, and up to once a day is pretty fast for me. :slight_smile:

Yep, I don’t use static for that project.

Yeah, I’m sure there is a way for it to work as you want with rsync. I haven’t run into that issue, but --checksum looks like it fixes it. :slight_smile:

So, Hugo has so many options that it’s easy to forget. We do sync modification date from /static to /public – so the FTP case should work.

2 Likes

Thanks very much. I read further into issues and it looks like the problems are solved some time ago.