Skip to content

Instantly share code, notes, and snippets.

@sbrauer
Last active August 29, 2015 13:56
Show Gist options
  • Save sbrauer/9237521 to your computer and use it in GitHub Desktop.
Save sbrauer/9237521 to your computer and use it in GitHub Desktop.
DNI Demo
# Add to ag/app/routes/routes.rb
get '/dni_demo/' do
zid = request.cookies['zid']
msg = zid ? "Your zid is #{zid}" : "You have no zid"
content_type 'text/javascript'
%{document.getElementsByTagName('span')[0].textContent = "#{msg}";}
end
@sbrauer
Copy link
Author

sbrauer commented Feb 26, 2014

To demo, add a script tag similar to the following just before closing body tag of http://primedia.railsplayground.net/dynamic-phone/:

<script src="http://local.apartmentguide.com/dni_demo/"></script>

Expected result:

Hello There
My phone number is Your zid is Nrk9zSwUwZS51b2elOoWwvHORQf.
Try to change it dynamically. I dare you.

Notes: This is a very quick and dirty jsonp-like approach. Since the cookie reading is done server-side, we'd have to be careful to avoid varnish caching issues. If varnish respects cache-control headers (I don't know) we could set No-Cache in the response.
Otherwise we might have to add the script tag dynamically and add a cache-busting query param.

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