davideast / hnpwa-api

CDN cached Hacker News API
https://api.hnpwa.com/v0/
82 stars 2 forks source link

API calls to .json URL are detected as static assets #8

Open pi0 opened 6 years ago

pi0 commented 6 years ago

Hey @davideast. Thanks for this great project. We use hnpwa-api (with a caching proxy on top of it) for nuxt/hackernews. Everything is fine and smooth. The only problem is that almost all website testers including webpagetest and PageSpeed Insights detect API calls to URLs ending with .json as static asset thus reducing final points even when adding cache headers!

image

I wonder if is it possible to make changes to provide URLs without .json extension or not? We can do such rewrites for nuxt-hackernews only but I think it may be useful for others too.


Deployed versions:

SSR: https://hn.nuxtjs.org SPA: https://hn-spa.nuxtjs.org

davideast commented 6 years ago

Hey @pi0! Thanks for the kind words, and thank you for Nuxt!

This is definitely possible through the firebase.json configuration. There's a few solutions here. I can make a change to the API, although it would be a breaking change to the v0 API. Or, if you're hosting your own server, you can re-write the .json calls to use "cleanUrls" so there's no extension.

Are you hosting your own API or using the HNPWA API at https://api.hnpwa.com/v0/news/2.json?

pi0 commented 6 years ago

Thanks, David for the answer. I'm proxy-passing requests down to the to the api.hnpwa.com and for sure both rewriting URLs and hosting are perfect ideas.

BTW for the change, Can't we add more routes without .json extension to the /v0`?