1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Serving js from another resource without breaking stuff

Discussion in 'Server Configuration and Hosting' started by yavuz, Feb 5, 2014.

  1. yavuz

    yavuz Well-Known Member

    I recently spend time optimizing my server and my sites. One of the things I did was serving static content from another (cookieless) domain. I had a domain laying around and wanted to use it and did.

    Most of the functionality was working as it is, until I installed the ul.x theme which has, for those who know, the ad styler. Unfortunately it requires the JavaScript loading from the main resource or needs some server modification. Mike @Audentio referred me to @MattW who although - unlike me - was using nginx, and kindly pointed me to the right direction, proving me his nginx solution:

      location /js/ {
      add_header Access-Control-Allow-Origin http://z22se.co.uk;
    From there on, I found many resources for this particular configuration but only were able to make one thing "partially" work by adding this code below into the sites .htaccess file:

    Header add Access-Control-Allow-Origin"*"
    Header add Access-Control-Allow-Methods:"GET,POST,OPTIONS,DELETE,PUT"
    While this helped the Ad Styler to open, you can't change anything, dropdowns are not working, can't select any color. Another problem occurred, another add-on @*******'s Modern Statistics stopped loading the messages & threads.

    I'd appreciate if any server guru's out there could help me solve this problem. Any suggestions, help is appreciated! Thank you.

    P.S: If you can make any sense of it, I saved two links to the resources:

    php - enable cors in .htaccess - Stack Overflow
    HTTP access control (CORS) - HTTP | MDN
  2. HittingSmoke

    HittingSmoke Active Member

    I don't have time to dig into it at the moment, but what you should do it fire up your javascript console and see exactly what is reported when you click the dropdowns that aren't working.

    My suspicion here is that the broken features require jQuery and your htaccess rules are loading the CDN-hosted javascript before jQuery is loaded. Javascript which requires jQuery must be loaded after the jQuery library is loaded.
    yavuz likes this.
  3. yavuz

    yavuz Well-Known Member

    When I switchd to Chrome, my code caused an internal server error, strangly not in firefox... So I couldn't check your suggesion out.
  4. HittingSmoke

    HittingSmoke Active Member

    Install the FireBug extension for Firefox. It includes a javascript console. Sounds like you've got a bigger problem on your hands though. Check your server logs to see what's going on when you load the page through Chrome. I stopped using Apache years ago so I'm a bit out of the loop with it. Good luck.

Share This Page