Skip to content

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

Merged
blittle merged 6 commits into
2023-01from
bl-add-route-cache
Mar 3, 2023
Merged

Add Cache-Control defaults to all the demo store routes#599
blittle merged 6 commits into
2023-01from
bl-add-route-cache

Conversation

@blittle
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown

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.

3 participants