Skip to content

Add an option to try a file based on Accept-Encoding #85

Description

@gajus

My webpack configuration compiles a .gz version of the scripts, though only if the compression reduces the file size, meaning that some .js scripts will have .js.gz counterpart, some will not.

I am able to tell nginx to try .gz in case of .js extension. Though, how'd I tell nginx to fallback to .js if .js.gz does not exist?

app.get('*.js', (req, res, next) => {
  // eslint-disable-next-line operator-assignment
  req.url = req.url + '.gz';

  res.set('Content-Encoding', 'gzip');

  next();
});

To complicate things further, I am using serve-static.

In nginx I'd be able to achieve this using:

try_files $uri.gz $uri @404

Repost: http://stackoverflow.com/questions/42602053/how-to-try-a-file-and-fallback-to-another-file

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions