Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): add config option to define etag hash function #6438

Merged
merged 6 commits into from
Sep 20, 2019

Conversation

pimlie
Copy link

@pimlie pimlie commented Sep 19, 2019

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

While looking into some benchmarks, @aldarund found out that generating the etag could snoop up a lot of processing time (especially with large html, ie extractCss: false). Further investigation found that the etag module uses SHA1 for generating a hash of the full html body.

This pr introduces a new config option render.etag.hash which users can use to implement their own etag hash function. Ie for etags it should often be fine to use a non-cryptographic hash function like murmurhash, which is multiple times faster with larger html body sizes.

Note: the render.etag.weak option is ignored when using the hook, user is responsible for implementing that.

Example for using murmurhash-native instead:

// nuxt.config.js
import { murmurHash128 } from 'murmurhash-native'

export default {
  render: {
    etag: {
      hash: html => murmurHash128(html)
    }
  }
}

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

@pimlie pimlie changed the title feat: add hook for overriding default etag hash feat(server): add hook for overriding default etag hash Sep 19, 2019
@codecov-io
Copy link

codecov-io commented Sep 19, 2019

Codecov Report

Merging #6438 into dev will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             dev    #6438      +/-   ##
=========================================
+ Coverage   95.6%   95.61%   +0.01%     
=========================================
  Files         79       79              
  Lines       2684     2693       +9     
  Branches     692      697       +5     
=========================================
+ Hits        2566     2575       +9     
  Misses       101      101              
  Partials      17       17
Flag Coverage Δ
#e2e 100% <ø> (ø) ⬆️
#fixtures 50.64% <30%> (-0.06%) ⬇️
#unit 92.31% <100%> (+0.02%) ⬆️
Impacted Files Coverage Δ
packages/config/src/options.js 100% <100%> (ø) ⬆️
packages/server/src/middleware/nuxt.js 97.36% <100%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 75f8564...bbb5dc1. Read the comment docs.

@pimlie pimlie requested review from aldarund and a team September 19, 2019 07:36
@pimlie pimlie changed the title feat(server): add hook for overriding default etag hash feat(server): add config option to define etag hash function Sep 20, 2019
pimlie and others added 2 commits September 20, 2019 19:17
Co-Authored-By: Pooya Parsa <pyapar@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants