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

Add Cache-Control defaults to all the demo store routes #599

Merged
merged 6 commits into from Mar 3, 2023

Conversation

blittle
Copy link
Contributor

@blittle blittle commented Feb 28, 2023

WHY are these changes introduced?

  1. Update Remix to 1.14.0
  2. Add Cache-Control defaults to all the demo store routes

WHAT is this pull request doing?

HOW to test your changes?

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes

Comment on lines +16 to +18
export const CACHE_SHORT = generateCacheControlHeader(CacheShort());
export const CACHE_LONG = generateCacheControlHeader(CacheLong());
export const CACHE_NONE = generateCacheControlHeader(CacheNone());
Copy link
Contributor

@frandiox frandiox Mar 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about doing this instead?

Suggested change
export const CACHE_SHORT = generateCacheControlHeader(CacheShort());
export const CACHE_LONG = generateCacheControlHeader(CacheLong());
export const CACHE_NONE = generateCacheControlHeader(CacheNone());
export const HEADERS_CACHE_SHORT = Object.freeze({'Cache-Control': generateCacheControlHeader(CacheShort())});
export const HEADERS_CACHE_LONG = Object.freeze({'Cache-Control': generateCacheControlHeader(CacheLong())});
export const HEADERS_CACHE_NONE = Object.freeze({'Cache-Control': generateCacheControlHeader(CacheNone())});

Then, in loaders we can just use {headers: HEADERS_CACHE_SHORT} instead of typing "cache-control" everywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not a bad idea, though it makes it a bit more complex to extend and define a custom header

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm .. I like what Bret have:

If we go for Fran's suggestion ...

// it's easy when nothing else is needed
json({}, {headers: HEADERS_CACHE_SHORT})

// it's weird when you need to add something else
json({}, {
  headers: {
    ...HEADERS_CACHE_SHORT,
    'some-header': 'value'
  }
})

whereas Bret's suggestion would be unambiguous

json({}, {
  headers: {
    'Cache-Control': HEADERS_CACHE_SHORT,
    'some-header': 'value'
  }
})

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How common is it to add extra headers, though? Wouldn't most of the times just be headers: HEADERS_CACHE_SHORT?
Plus, even in that situation I'd personally still prefer writing ... than 'Cache-Control' since for some reason I always misspell header names 😂

But just a random idea though, the current version is good as well 👍

Comment on lines +16 to +18
export const CACHE_SHORT = generateCacheControlHeader(CacheShort());
export const CACHE_LONG = generateCacheControlHeader(CacheLong());
export const CACHE_NONE = generateCacheControlHeader(CacheNone());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm .. I like what Bret have:

If we go for Fran's suggestion ...

// it's easy when nothing else is needed
json({}, {headers: HEADERS_CACHE_SHORT})

// it's weird when you need to add something else
json({}, {
  headers: {
    ...HEADERS_CACHE_SHORT,
    'some-header': 'value'
  }
})

whereas Bret's suggestion would be unambiguous

json({}, {
  headers: {
    'Cache-Control': HEADERS_CACHE_SHORT,
    'some-header': 'value'
  }
})

@frandiox frandiox mentioned this pull request Mar 3, 2023
@blittle blittle merged commit bceddb4 into 2023-01 Mar 3, 2023
@blittle blittle deleted the bl-add-route-cache branch March 3, 2023 14:33
@github-actions github-actions bot mentioned this pull request Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants