Cross-Domain Caching

Per Buer perbu at varnish-software.com
Wed Jun 11 21:26:08 CEST 2014


Hi Diego.

What you need to understand is how the server which you are embedding the
content from works. It will not serve up the right content unless you give
it the right Host: header (
https://www.varnish-software.com/blog/getting-virtual-hosts-right-varnish-cache
explain how virtual hosts actually works).

The thing you are missing is something like this:

sub vlc_recv {
  if (req.http.host ~ "infographics.estadaodados.com") {
     set req.http.host = "example.com";
     # could also override req.url here - but better to keep req.url the
same (for simplicity).
     set req.backend_hint = infograph;
  }



On Wed, Jun 11, 2014 at 8:10 PM, Diego Rabatone <diraol at diraol.eng.br>
wrote:

> Hi James and Per,
>
> thank you very much for answering my question.
>
> First of all, I have the permission to embed the content. All embeds are
> from websites that are offer the service of building data visualizations
> and infographics, me and my team use them to build our products and they
> all have embeding options.
>
> I like the option to only revalidate the contet, instead of refetching it,
> but I didn't understand completly how could I do it Per.
>
> I will try and example, tell me if I'm making any conecptual mistake.
>
> My cached domain is: *estadaodados.com <http://estadaodados.com>* , this
> is were I have full control and where my Varnish is.
>
> On *estadaodados.com/iframe <http://estadaodados.com/iframe>* I want to
> embed, using an Iframe, a page from *example.com <http://example.com>*,
> exactly this page: *example.com/123* <http://example.com/123>
>
> So, instead of using *<iframe src="http://example.com/123
> <http://example.com/123>"></iframe>*
> I should set *example.com <http://example.com>* as a *backend* on my
> varnish with:
>
> backend infograph {
>     .host="example.com"
> }
>
> And set this vcl_recv rule:
>
> sub vlc_recv {
>   if (req.http.host ~ "infographics.estadaodados.com") {
>      set req.backend_hint = example.com
>   }
>
> And then use the iframe with:
>
>
> *<iframe src="infographics.estadaodados.com/123
> <http://infographics.estadaodados.com/123>"></iframe> *
>
> That's it?
>
> Thanks for your attention,
>
> Best,
>
>
> --------------------------------
> Diego Rabatone Oliveira
> diraol(arroba)diraol(ponto)eng(ponto)br
> Identica: (@diraol) http://identi.ca/diraol
> Twitter: @diraol
>
>
> 2014-06-10 3:55 GMT-03:00 Per Buer <perbu at varnish-software.com>:
>
>  Hi Diego,
>>
>>
>> On Tue, Jun 10, 2014 at 1:24 AM, Diego Rabatone <diraol at diraol.eng.br>
>> wrote:
>>
>>> Hi friends,
>>>
>>> I am new at the caching World, and I have looked for some solution to
>>> cross-domain caching, but I have not found any solution.
>>>
>>> I have a blog that embed some dataviz webservices, and I want to cache
>>> this content that I insert using Iframes.
>>> The blog is: http://blog.estadaodados.com there is any way of doing
>>> this?
>>>
>>
>> Absolutely. It is a pretty good way to make sure that the content you
>> embed performs well in addition to lessening the load on the server you are
>> embedding content from.
>>
>>
>>> At this moment I have a Varnish + nginx + php-fpm setup on a dev server
>>> (not the link that I posted), and it seems to be working ok, but there is
>>> no caching of the Iframes.
>>>
>>
>> No. This is expected. In order to cache those iframes you would need to
>> set up the server you embedding content from as a backend on your varnish
>> and preferably give it a new hostname. Then, in the vcl_recv you replace
>> req.http.host to the original hostname and set the backend. Then regular
>> caching rules will be applied. In Varnish 4.0 you could set the cache time
>> to one hour and you could add a keep of maybe a couple of hours. That will
>> enable IMS so you wouldn't have to refetch the content, only revalidate it.
>>
>>
>> As James said, should make sure you have the authors permission, but if
>> you do it through Varnish at least there won't be much of a impact on their
>> server when you do this.
>>
>> Cheers,
>>
>> Per.
>>
>> --
>>  <http://www.varnish-software.com/> *Per Buer*
>> CTO | Varnish Software
>> Phone: +47 958 39 117 | Skype: per.buer
>> We Make Websites Fly!
>>
>> Winner of the Red Herring Top 100 Global Award 2013
>>
>>
>>
>


-- 
 <http://www.varnish-software.com/> *Per Buer*
CTO | Varnish Software
Phone: +47 958 39 117 | Skype: per.buer
We Make Websites Fly!

Winner of the Red Herring Top 100 Global Award 2013
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20140611/ba72db48/attachment-0001.html>


More information about the varnish-misc mailing list