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

🚀 [Feature]: Add config option to Static config to disabled cache on Index routes #2136

Closed
3 tasks done
nathanfaucett opened this issue Oct 4, 2022 · 1 comment · Fixed by #2140
Closed
3 tasks done

Comments

@nathanfaucett
Copy link
Contributor

Feature Description

Add config option to Static config to disabled cache on Index routes, use case is single page apps that need the index.html files to use no-cache, no-store, must-revalidate or add a func to the Static config that allows the header to be customized based on the file or path.

Additional Context (optional)

No response

Code Snippet (optional)

package main

import "github.com/gofiber/fiber/v2"
import "log"

func main() {
  app := fiber.New()
  
  // custom function
  app.Static("/", "./.github", Static{CacheControl: func(c *Ctx) string {
    if strings.HasSuffix(c.Path(), "index.html") {
		return "no-cache, no-store, must-revalidate"
    } else {
		return ""
    }
  }})
  // or just a boolean to disable on index.html
  // would set the `Cache-Control` header to no-cache, no-store, must-revalidate for `index.html` files
  app.Static("/", "./.github", Static{IndexDisableCache: true}

  log.Fatal(app.Listen(":3000"))
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my suggestion prior to opening this one.
  • I understand that improperly formatted feature requests may be closed without explanation.
@welcome
Copy link

welcome bot commented Oct 4, 2022

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

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

Successfully merging a pull request may close this issue.

2 participants