The Dev Blog

Putting Family Management on Rails!

Assets Servers, JavaScript and CSS - A Dangerous Mix

Posted by Guy Naor Sun, 18 Mar 2007 08:43:00 GMT

To make Famundo load faster, we implemented asset servers - 4 of those - to let the client open more connections simulatenously and so load everything much faster. If you want to see the reasoning, check out this explanation. Rails edge currently implement that as well. We even went a step further, and we can serve the static content either from our data center, or from Amazon's S3. This, in conjunction with packing and compressing on the JS/CSS files gave us a huge speed boost.

But while testing it, we discovered a very interesting problem, that is a result of the JavaScript security model in the browsers. All the regular stuff works with no incident, as we use the same main domain for both the main servers and assets servers, the browsers are happy. But one thing won't work - accessing the actual stylesheets from withting JavaScript. We have code that does something along this lines:

var ss=document.styleSheets[i];
var cssRules=ss.cssRules?ss.cssRules:ss.rules;

We use that to get at some colors stored in the CSS, as we support multiple themes. And yes, we could have used different methods, but this is just a sample of actually accessing the CSS files. This results in the JavaScript error "Access to restricted URI denied". The fix is simple - load the CSS from the same place you load the main content. Or don't access the CSS files directly from JavaScript.

So if you have similar constructs, be warned it might cause errors.

Posted in  | no comments

del.icio.us:Assets Servers, JavaScript and CSS - A Dangerous Mix digg:Assets Servers, JavaScript and CSS - A Dangerous Mix spurl:Assets Servers, JavaScript and CSS - A Dangerous Mix wists:Assets Servers, JavaScript and CSS - A Dangerous Mix simpy:Assets Servers, JavaScript and CSS - A Dangerous Mix newsvine:Assets Servers, JavaScript and CSS - A Dangerous Mix blinklist:Assets Servers, JavaScript and CSS - A Dangerous Mix furl:Assets Servers, JavaScript and CSS - A Dangerous Mix reddit:Assets Servers, JavaScript and CSS - A Dangerous Mix fark:Assets Servers, JavaScript and CSS - A Dangerous Mix blogmarks:Assets Servers, JavaScript and CSS - A Dangerous Mix Y!:Assets Servers, JavaScript and CSS - A Dangerous Mix smarking:Assets Servers, JavaScript and CSS - A Dangerous Mix magnolia:Assets Servers, JavaScript and CSS - A Dangerous Mix segnalo:Assets Servers, JavaScript and CSS - A Dangerous Mix

Comments

Comments are disabled

Subscribe to The Dev Blog