-
Notifications
You must be signed in to change notification settings - Fork 308
Conversation
Instead of depending on `make css` to rebuild css, this calls scss dynamically whenever gittip.css is requested.
This lets us use the production file in local development, parallel to how we use a cloud db at first.
Thought I had done this. Oh, well.
Next step is to either:
|
Does this perform acceptably well? For me, I'll want to run it (which I'm not going to manage today) before merging this. Others are welcome to merge as they see fit. |
@bruceadams It performs acceptably well in development. Sass does its own caching (one of the reasons I decided to go with the original sass tool instead of a libsass-based alternative). I haven't benchmarked it, however, so I'm not sure how it will look in production. Long-term we'll end up with a CDN, anyway. |
To be clear: this is not ready to merge yet. We're not ready to deploy this without further work as mentioned above (buildpack or CDN). Therefore merging this to master right now would be a bad idea. :-) |
Seems that the way forward actually involves both installing sass at Heroku and using a CDN. I've set up a CDN w/ MaxCDN (closing #866), which uses https://www.gittip.com/assets/ as it's origin server. Here's an example of an asset served from this new CDN: https://assets-gittipllc.netdna-ssl.com/9.4.7/gittip.css Now we need to dynamically generate that file from the origin server and we're all set, and that means installing sass at Heroku. I've ticketed writing a custom buildpack as #1257 and will circle back here after that lands. |
This hook is part of heroku-buildpack-python. ht @btubbs and @kennethreitz
I changed the gittip.css simplate to 404 if the version requested doesn't match the current version of the app, so that we don't accidentally serve CSS that's out of sync with our markup. Without this we'd actually have a potential attack vector, in that someone could prefill our CDN cache with the current version of the CSS by requesting future versions from the CDN that would be served with the current version by the origin server. For development we don't want to require sass out of the box, and so we want to be able to point to a CDN-hosted CSS file by default. Since the version in development won't match the version in production, I added an out: if you specify '-' as the version you won't get a 404, you'll get the file. This changes default local.env to take advantage of that.
@bruceadams @clone1018 I'm ready to review and merge this when one of yinz gets a chance. I ended up installing https://gittip.whit537.org/assets/-/gittip.css We've got a CDN set up that uses |
We had a cache_static module but I turned it off because it was misbehaving: https://botbot.me/freenode/gittip/msg/4196280/. I'm bringing these hooks back because it looks like we need to configure cache headers to make it work with MaxCDN. There are facilities in the MaxCDN dashboad for working around various issues, but they don't appear to be working for me, and I'm getting less than stellar response from the on-page live chat over there. So this is me trying to change the headers at the origin so we start seeing cache hits at MaxCDN. I've set up a pull zone for QA at MaxCDN so we can fully test this front to back before deploying to production.
What if someone has a username assets-oh-yeah-assets?
Okay @bruceadams @buttscicles @trinary @clone1018 @wyze @twolfson this is ready for some pounding: I brought back the https://assets-qa-gittipllc.netdna-ssl.com/9.4.7-dev/gittip.css That's at MaxCDN with this as the origin: https://gittip.whit537.org/assets/9.4.7-dev/gittip.css I'm seeing
@clone1018 Let's make sure we don't see the flakiness you were seeing before. I believe that was caused by reset.css not being loaded properly; that file is in /assets/ but not in /assets/%version/. We should particularly pay attention to how this interacts with |
|
||
response.headers.cookie.clear() | ||
|
||
if 'version' in uri.path: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this cache indefinitely in development too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch. I'd prefer not to start switching features on the version string, but rather to maintain finer-grained configuration by adding more environment variable knobs. I've added a GITTIP_CACHE_STATIC
knob which is set to no
in default_local.env
.
Wouldn't it be better to compile and upload the css to the CDN as part of the deploy script? |
Conflicts: www/assets/%version/gittip.css
This controls whether to set Expires for versioned resources under /assets/.
Perhaps. MaxCDN has two "zone" types: push and pull. They steer towards pull zones for assets, and push zones for large binary files. Of course there's no technical reason (that I'm aware of) we couldn't use a push zone for assets. By generating CSS dynamically on the server, we introduce sass as an additional runtime dependency, which makes our slugs heavier and increases our surface area for potential vulnerabilities. We also add complexity to the build process because we have to install sass (I did this in a post_compile hook). If we generate CSS dynamically at release time and push to our CDN, then we add release-time complexity. We can fail to upload the assets (network issues, API issues, etc.) and we would have to code defensively against that in Note that The fact is that we can't escape the run-time complexity, because we need to provide a good developer experience, and quickly compiling assets on the fly is the ideal way to do that. The good news is that this complexity gets exercised often by many developers. Exercise keeps a system healthy. If we introduce similar complexity at release time then it a) introduces duplication, and b) only gets exercised at release time, and then only by approximately one person. I think we want to go with pull. |
Conflicts: configure-aspen.py
Intense testing session here: https://botbot.me/freenode/gittip/msg/4960178/ |
You want to go with pull. It's easier. It's handier. You might find this useful for more context: http://wimleers.com/article/key-properties-of-a-cdn. |
Conflicts: www/assets/%version/gittip.css
This builds gittip.css on the fly from SCSS sources when it's requested rather than having to call:
watch -n1 make css
or
sass --watch scss/gittip.scss:www/assets/%version/gittip.css