Giter Site home page Giter Site logo

consumes more bandwidth about webp_server_go HOT 3 CLOSED

webp-sh avatar webp-sh commented on July 20, 2024 1
consumes more bandwidth

from webp_server_go.

Comments (3)

BennyThink avatar BennyThink commented on July 20, 2024

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
image

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:

  1. we already have one cache webp image
  2. remote side has update the image for one same URL.
  3. we would then return old webp which is not update-to-date.

So in general, this is intended.

from webp_server_go.

thetrueself avatar thetrueself commented on July 20, 2024

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.

BennyThink avatar BennyThink commented on July 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.