Using ColdFusion Ajax libraries on a remote server

Michael asked:

So having common JavaScript files "in the cloud" and referencing them in your code as absolute urls is becoming more common. Is there a way to have CF point to the EXT-JS files hosted by a third party?

My initial answer to this question was no. I knew that the ajaxImport tag supported a scriptSrc attribute. According to the docs, this specifies a folder, relative to the web root, where the relevant JavaScript files will be loaded.

On a whim though, I tried a full path:

<cfajaximport scriptsrc="http://www.cnn.com/foo/" tags="cfwindow" />

Surprisingly, this not only didn’t throw out an error, it actually worked. By “work” of course I mean it used the URL prefix as I set it:

script type="text/javascript" src="http://www.cnn.com/foo/ajax/messages/cfmessage.js"></script> <script type="text/javascript" src="http://www.cnn.com/foo/ajax/package/cfajax.js"></script> <script type="text/javascript" src="http://www.cnn.com/foo/ajax/yui/yahoo-dom-event/yahoo-dom-event.js"></script> <script type="text/javascript" src="http://www.cnn.com/foo/ajax/yui/animation/animation-min.js"></script> <script type="text/javascript" src="http://www.cnn.com/foo/ajax/ext/adapter/yui/ext-yui-adapter.js"></script> <script type="text/javascript" src="http://www.cnn.com/foo/ajax/ext/ext-all.js"></script> <script type="text/javascript" src="http://www.cnn.com/foo/ajax/package/cfwindow.js"></script> <link rel="stylesheet" type="text/css" href="http://www.cnn.com/foo/ajax/resources/ext/css/ext-all.css" /> <link rel="stylesheet" type="text/css" href="http://www.cnn.com/foo/ajax/resources/cf/cf.css" />

None of these URLs will actually work, but if they did, it looks as if scriptSrc would be an appropriate way to load them. I tend to get a bit anal about not following the CF docs to the letter of the law, but I can’t see any reason why Adobe would stop this behavior.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com

Comments