Comments (3)
Upon each request, we're using head method to get response headers. We need to do it in the first place because we don't know if the image has been changed.
HEAD method is lightweight, because it only contains http headers. 209B in this example
For your recommendation, there's a paradox:
instead of requesting the original picture first, find the webp file according to etag.
we need to know etag, then we can find webp image, and in order to find etag we need to request to remote.
And think of one edge case:
- we already have one cache webp image
- remote side has update the image for one same URL.
- we would then return old webp which is not update-to-date.
So in general, this is intended.
from webp_server_go.
Although the head method does not return content, frequent establishment of http requests is also a resource consumption. Due to the very low frequency of image changes with the same name, it is recommended to add the cache time configuration (optional parameter) to the configuration file. During the cache time, if the webp has been generated, there is no need to request the source image address.
from webp_server_go.
Your cache time
is a fixed value, which is unstable - by saying unstable I mean how could you make sure that the time you set will always return the correct image? It may be true on most cases, but I'm not wiling to take the chance.
And further more, let's track back to local mode
STAT, err := os.Stat(RawImagePath)
ModifiedTime := STAT.ModTime().Unix()
// webpFilename: abc.jpg.png -> abc.jpg.png.1582558990.webp
WebpFilename := fmt.Sprintf("%s.%d.webp", ImgFilename, ModifiedTime)
We have a few lines of code to get the modification time of one image, to help us keep track of whether our webp was outdated.
On remote mode, we take advantages of etag
and that makes the behavior consistent - and this is as stable as ModTime()
.
Possibly we make take advantages of standard http cache headers like Cache-Control: max-age=31536000
or Last-Modified
. But again, etag
is one kind of cache validation mechanism and we're using it.
ref: https://developer.mozilla.org/en-US/docs/Web/HTTP/Caching
from webp_server_go.
Related Issues (20)
- Variable Compression Size Depending on File Size HOT 6
- Checking if imageHeightWidthRatio is not zero before dividing HOT 2
- -dump-config flag does not work with Docker image HOT 2
- Empty file causes runtime error when it is expected to be a directory HOT 2
- Can't get webp_server_go work HOT 5
- Requests with too large headers fields are not logged HOT 4
- NEF image size is wrong and extra parameters are invalid HOT 5
- Delete older files from storage HOT 2
- Clear older files autometically HOT 2
- Image not found! HOT 2
- Readme broken link HOT 1
- Exclude certain sub folder HOT 1
- A problem converting GIF images to AVIF format HOT 6
- set maxWidth and/or maxHeight HOT 9
- When the instantaneous request volume is large, a large amount of CPU and memory will be consumed. HOT 1
- Couldn't load xx.ico file HOT 3
- How do I configure and exclude links in MP4 format? HOT 5
- Server don't conversions images to jxl format in Firefox Nightly HOT 3
- Cropping mode environment variable HOT 4
- Directory traversal with malformed HTTP request HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webp_server_go.