AddRemote method is not downloading the javascript files for the CDN for Squishit - asp.net-mvc-2

I am using SquishIt for bundling and minification of css and js files in a asp.net mvc2 application.
I have used AddRemote method to download the jquery-1.7.1.min.js and jquery-ui-1.8.17.min.js from CDN in the release mode, but still I am seeing that the files are downloaded from the local copy instead from the CDN in release mode.
Code:
public static MvcHtmlString PackageLibs(this HtmlHelper htmlHelper)
{
var client = Bundle.JavaScript()
#if DEBUG
.Add("~/scripts/jquery-1.7.1.js")
.Add("~/scripts/jquery-ui-1.8.17.js")
#else
.AddRemote("~/scripts/jquery-1.7.1.min.js",
"http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js",true)
.AddRemote("~/scripts/jquery-ui-1.8.17.min.js",
"http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js",true)
#endif
.ForceDebug()
.Render("~/scripts/combined.js");
return new MvcHtmlString(client);
}
Screenshot:
Can anyone help me to know what is creating the issue?

Related

kaltura plugin external resource

I am currently making an external plugin for kaltura video player. To embed the plugin in the video player we have set some variables in the flashvars such as:
"flashvars": {
"myComponent":{
"plugin":true,
"iframeHTML5Js" : "plugin.js"
}
}
I want to place my plugin.js at an external resource such as CDN or through github. Is there any way to do this?
Also, is there a way to reference the plugin code in the page itself without the need of a path to access it?
You can update it in the studio under ui vars - you can point to a cdn url there.
we dont allow external url from client flashvar configuration

How to include 3rd party JavaScript libraries in a reusable gwt library/widget?

I'm trying to get my feet wet with GWT to see if migrating will work out. I usually try the more difficult parts first to make sure I can finish the project. The most difficult part of my project(s) is referencing 3rd party JS libs. In this example I'm trying to use PubNub as much of our platform uses it.
What I'd like to do is create a reusable object that can be used in other GWT projects in need of PubNub. I've got a simple little test running successfully (ie, I've got the basics of JNSI working), but my question is -> where do I put the reference to the 3rd party script in order to create the library/module properly?
Right now I just put the reference to the external scripts in the HTML page in the project, but I'm pretty sure this is incorrect from a reusability perspective, as this lib would be used in other projects, each of which would have their own base HTML page.
I tried putting the reference in the gwt.xml file, but this seems to lose the references (ie my test project no longer works as it did when the scripts were in the HTML page)
Do you have any tips on how to include 3rd party libraries in a reusable GWT library/widget?
Here you have an example using client bundles and script injector, you can use either synchronous loading or asynchronous.
When using sync the external js content will be embedded in the application, otherwise it will be include in a different fragment which will be got with an ajax request.
You can put your api in any server and load it with the ScriptInjector.
public class Example {
public static interface MyApiJs extends ClientBundle {
MyApiJs INSTANCE = GWT.create(MyApiJs.class);
#Source("my_api.js")
TextResource sync();
#Source("my_api.js") // Should be in the same domain or configure CORS
ExternalTextResource async();
}
public void loadSync() {
String js = MyApiJs.INSTANCE.sync().getText();
ScriptInjector.fromString(js).inject();
}
public void loadAsync() throws ResourceException {
MyApiJs.INSTANCE.async().getText(new ResourceCallback<TextResource>() {
public void onSuccess(TextResource r) {
String js = r.getText();
ScriptInjector.fromString(js).inject();
}
public void onError(ResourceException e) {
}
});
}
public void loadFromExternalUrl() {
ScriptInjector.fromUrl("http://.../my_api.js").inject();
}
}
[EDITED]
A better approach is to use a new feature in gwtquery 1.4.0 named JsniBundle. We introduced this feature during the GWT.create conferences at San Francisco and Frankfurt.
With this approach you can insert any external javascript (placed in your source tree or hosted in an external host) as a JSNI block. It has many benefits:
Take advantage of GWT jsni validators, obfuscators and optimizers.
Get rid of any jsni java method when the application does not use it.
The syntax is actually easy:
public interface JQueryBundle extends JsniBundle {
#LibrarySource("http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js")
public void initJQuery();
}
JQueryBundle jQuery = GWT.create(JQueryBundle.class);
jQuery.initJQuery();

GWT inject script element into the html file

On my gwt project. i have a script that call the dictionary:
<script type="text/javascript" src=conf/iw_dictionary.js></script>
instead of writing this script element in the html file. i want to inject it into the html from the entry point, on the module load.
how can i do it?
Use com.google.gwt.core.client.ScriptInjector, since it was created specifically for stuff like this
ScriptInjector.fromUrl("conf/iw_dictionary.js").setCallback(
new Callback<Void, Exception>() {
public void onFailure(Exception reason) {
Window.alert("Script load failed.");
}
public void onSuccess(Void result) {
Window.alert("Script load success.");
}
}).inject();
Basically you inject the script element in your onModuleLoad():
Element head = Document.get().getElementsByTagName("head").getItem(0);
ScriptElement sce = Document.get().createScriptElement();
sce.setType("text/javascript");
sce.setSrc("conf/iw_dictionary.js");
head.appendChild(sce);
The browser will automatically load it as soon as it's injected.
You could simply add a <script> element in your *.gwt.xml file.
<script src='conf/iw_dictionary.js' />
onModuleLoad will only be called once the script is loaded (as if you had it in your html page).
The answers form jusio, Dom and Thomas Broyer are all valid here. In my particular case, I was looking to inject a series of polyfill scripts into GWT for some IE8 support we needed when running native JS code. The polyfill scripts needed to be available to the GWT iframe's window context - NOT the host page. To do that, using ScriptInjector was the correct approach as it attaches the script at that level. You can make ScriptInjector install the scripts to a host window by using setWindow(TOP_WINDOW). Adding scripts with the <script> tag in my *.gwt.xml file seemed to be attaching to the host window as did using #Dom's approach.

GWT: deferred loading of external JS resources

I have a widget depending on some external JS files, and I'd like to lazy load all these external resources. I've already used code splitting to lazy load the GWT code that concerns the widget, but the JS files defined in the gwt.xml, using the script tag, are loaded anyway, which is not desirable.
Is there a standard GWT way of loading these external resources on demand? I can do it myself using raw JS, but I'd rather not spend time on this too.
I think you'll want to take a look at the com.google.gwt.core.client.ScriptInjector class. From the javadocs:
Dynamically create a script tag and attach it to the DOM.
...
Usage with script loaded as URL:
ScriptInjector.fromUrl("http://example.com/foo.js").setCallback(
new Callback<Void, Exception>() {
public void onFailure(Exception reason) {
Window.alert("Script load failed.");
}
public void onSuccess(Void result) {
Window.alert("Script load success.");
}
}).inject();
This code can of course be invoked from within your split points, or indeed anywhere in your code.
ScriptInjector is quite portable. It doesn't have any external dependencies, so you should be able to backport it into your 2.3 application without much problem.

GWT FileUpload doesn't work on Chrome and Opera

Hi
I have some appliacation written in GWT 2.2 (tested also on previuos versions) with file upload. Basicly there is FileUpload component with Struts servlet on server side. The problem is that it works fine on IE and FF, but does not work on Chrome and Opera.
I found some tip to use gwtupload library ( i build the simplest case ) and the problem still occurs... With gwtupload I get alert with:
"Error, your browser has not sent any information. Please try again or try it using another browser"
Simple code for gwtupload version:
defaultUploader = new SingleUploader();
verticalPanel.add(defaultUploader);
defaultUploader.addOnFinishUploadHandler(onFinishUploaderHandler);
// Load the image in the document and in the case of success attach it to the viewer
private IUploader.OnFinishUploaderHandler onFinishUploaderHandler = new IUploader.OnFinishUploaderHandler() {
public void onFinish(IUploader uploader) {
if (uploader.getStatus() == IUploadStatus.Status.SUCCESS) {
//new PreloadedImage(uploader.fileUrl(), showImage);
// The server can send information to the client.
// You can parse this information using XML or JSON libraries
// Document doc = XMLParser.parse(uploader.getServerResponse());
// String size = IUploader.Utils.getXmlNodeValue(doc, "file-1-size");
// String type = IUploader.Utils.getXmlNodeValue(doc, "file-1-type");
Window.alert("Upload work");
}
}
};
Deafult servlet on the serves side.
Again, it works only on FF and IE. I hope somebody faced similar problem. :)
It could be some nasty WebKit bug. I think to remember something about a problem uploading files with WebKit-based browsers on OS X. You may want to check the WebKit bug database.