Support

Admin Tools

#18466 Google CDN Access

Posted in ‘Admin Tools for Joomla! 4 & 5’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

Joomla! version
n/a
PHP version
n/a
Admin Tools version
n/a

Latest post by nicholas on Thursday, 12 December 2013 01:00 CST

user77157
Hello. I'm trying to allow the Google CDN JQuery Library site in my htaccess file and can't seem to get it to work. I have other links allowed already, which work well, and the code I have in my custom header section of the htaccess file for that is as follows:

SetEnvIf Origin "^http(s)?://(.+\.)?(site1\.com|site2\.com)$" origin_is=$0
Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is


The Google CDN URL I need to allow is this: https://ajax.googleapis.com/ajax/libs/jquery/1.9/jquery.min.js

So I updated the code to read as follows:

SetEnvIf Vary Origin "^http(s)?://(.+\.)?(site1\.com|site2\.com|.googleapis\.com)$" origin_is=$0
Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is

However, that code is not working - I'm still getting a "failed to load resource" error. I'm still a noob when it comes to htaccess, but I have been teaching myself. I've searched through the Admin Tools User Guide, the support ticket postings, w3's section on Access-Control-Allow-Origin, and a general google search both with and without "site: akeebackup.com" as part of the options as requested. I'm obviously not getting it. Any advise?

Thank You
Angela
Degarrin

nicholas
Akeeba Staff
Manager
I am not sure what you are trying to do or why. Loading jQuery from a CDN with HTTPS prefix always works and is never blocked by browsers. Perhaps I am not understanding the use case. Can you please point me to the page where it explains what code you need to put in your .htaccess and why?

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

user77157
Well, the goal was to load a remote copy of jquery from the Google CDN instead of using a local copy. I use a plugin for that called "Jquery Loader" from Joomseller, which allows you to choose from different versions of jquery (local or remote copies), remove mootools conflicts, etc. It is the latest remote copy that throws an error when trying to load; can't access the file. The error message is like the one I sometimes get when trying to allow exceptions in the .htaccess file and I thought it wasn't allowing the site through from the outside source. I had this problem with google.com before and adding the code I gave in my first post fixed it. I got that code from the following (it's the 6th main suggestion on the page): http://stackoverflow.com/questions/1653308/access-control-allow-origin-multiple-origin-domains

But I thought on it some more overnight and after reading your reply too, I tested two more things:

1. Disabled the Admin Tools Plugin. This had no effect on the issue. I know that disabling the plugin turns off the firewall, but would it also disable any rules set in the htaccess file? I wouldn't think so, but can you tell me for certain? However, it may be moot based on #2

2. Tried loading a different jquery remote version. A different remote version was allowed through the firewall without issue. This baffles me, quite honestly, because the plugin is using the same php file to pull in whichever remote copy I pick, and the remote copy I want does appear to be a valid version based on the jquery website. But baffled or not, I'm aware this is something I need to discuss with the jquery plugin's developer.

So after all that, it looks like I may have gone down the wrong path to begin with and tried to make things a lot more complicated than they needed to be. *sigh*

Thank You
Angela

nicholas
Akeeba Staff
Manager
> So after all that, it looks like I may have gone down the wrong path to begin with and tried to make things a lot more complicated than they needed to be. *sigh*

That's exactly what I was thinking.

I am redesigning our site and I am, too, exploring the possibility of loading jQuery from a CDN. I'm using the CDN recommended by jQuery without a problem. No .htaccess file can prevent a file from an external location to be loaded.

As for the origin business, this is called CORS. It has to do with XMLHttpRequest (AJAX) requests across different domain names. In other words it doesn't have to do with loading the jQuery library itself, it has to do with whether you can use a jQuery-based Javascript script on Site A to pull data from Site B through AJAX. This is useful if you want to build an application based on web services, but in your case it has absolutely nothing to do with the issue you had. Since you were saying that you weren't able to load jQuery I was wondering "so why the heck is he trying to set up CORS?!". Now I know, it was a misled attempt to solving the wrong problem :)

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

user77157
Thank you for the explanation and the link, it is helpful and appreciated!

Angela

nicholas
Akeeba Staff
Manager
You're welcome, Angela!

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!