How to cache asset stored on Google Cloud Storage?


#1

Hello,

How can I cache assets stored on google cloud storage (GCS)? I’ve been trying to make it work in the past 2 days with no luck. My website have backend & frontend, and the assets is stored on GCS. I tried the following guide:

Here’s what I did:

  1. I created a bucket on GCS ‘img.mywebsite.com
  2. On Cloudflare I set CNAME with the following:
    Name: img
    Value: c.storage.googleapis.com
  3. I set all object in GCS bucket ‘readable by public’

The Image is still not served via Cloudflare and there’s no CF status on the header of the assets. Am I missing something? I would really appreciate any input.

Thank you.


#2

Have you set :orange: in your DNS settings?


#3

Yes, I have turned it on. Cloudflare is caching the content served from my servers, but not from GCS.


#4

What IP address does the host resolve to?


#5

Assets still being served from 216.58.221.80 (Google)


#6

Can you post your domain and a screenshot of the DNS entry in question (redact any sensible information, such as your own IP addresses).


#7

Sure, here’s the screenshot.


#8

You should say also the domain, it’s useless otherwise.


#9

Sorry, I can’t share the domain because it’s for internal use.


#10

Then there is nothing we can do, without seeing what it’s happening… Can you at least share the headers of a request?


#11

Your site requires a login to even access the page on the main site and on the subdomain displays no images…

Perhaps you need to refresh your DNS. The record is orange clouded so it resolves to a Cloudflare IP.


#12

It should resolve to Cloudflare because it is orange or it does resolve to Cloudflare because “it does” (you checked)?

If it does it most likely is a caching issue as @user7121 wrote it still resolves to Google’s address.


@user7121, are you sure that would work in the first place? The request to Google does not require c.storage.googleapis.com in the host header?


#13

In theory it should work, they allow it: https://cloud.google.com/storage/docs/hosting-static-website

They even tell you to use a third-party CDN for HTTPS.


#14

Fair enough, thanks. So it should work and the question is why would he get the actual IP address when the system is properly configured (as @cscharff hinted). Maybe really caching, I’d wait a bit more.


#15

Could it also be that for some reason there is a no-cache on the bucket?


#16

It’s caching for 3600s


#17

You can check the domain: https://mfsstg.net

The image is still served through GCS instead of Cloudflare.

DNS screenshot:

Header screenshot:


#18

That host does resolve to Cloudflare. Check out http://sitemeer.com/#img.mfsstg.net

The problem in your case is, you probably link somewhere without a proper protocol scheme, which turns your link into a relative one with the host appended to the original Google link. Have a thorough look at the link you are requesting.


#19

I thought I should see “CF-Status” on the header everytime it goes through Cloudflare network? Could you please elaborate which link are you referring to? If you’re referring to the asset link, I just make the object viewable on GCS and it automatically provide me with the link.


#20

The request you posted goes to a Google server. What were you trying to show with it?