Ajax CDN support for ajaxcontroltoolkit - javascript

I am using ajaxcontroltoolkit in my web forms application. I have added ToolkitScriptManager in my master page like below;
<ajaxToolkit:ToolkitScriptManager runat="server" />
and the following lines are generated;
<script src="/WebResource.axd?d=Jibl3MtI-Z0SnbWFojUORizoN9Crh5ry8NMfzJSSnoTf-UFTKFjMJ64T1LoJzsMiy-3x84ZOv4fPul5Ovf0hWqKfvas1&t=634361805716190000" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=GaKMM7fT3pJ-STBLsG7RA9G19YL8-8Qwn55cEa789OnUZnJVo7k-lHiGlv-78SX_-jNa1e8ggtiMU1q11qL5p_Ds-x2fGN94tSQ_LiVmXw5rZT5JLvwPijiZtGc4sjeI6qyDWl6iPDaSvOI5BxUFSYMrocQ1&t=ffffffff88dd8486" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=5-e4xi7M2z7nkjzlbU8-TWOpW3pG-5yWTc1gjU27ASzLUO3z3X6ekk3Sni1yPjhQTHZqsYZzKxrYCi_Gka_qck67rCoY74phG4J0hnrafob5PPfGsqMiXsHm5iwUWoAf11fyGw2&t=11e6618b" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=QuFbQ1DExlSpNLIb-yKHF9rpmtXEsaZy3mY1kUywoGagqJwlk39ehRy6UMfloAvfPq5iKspCQd3hr6z2WtLRfs2vX5cK8IhsLTmXS2C608YECG519GPA63CN6_5IYjb9Or0HIg2&t=11e6618b" type="text/javascript"></script>
<script src="/default.aspx?_TSM_HiddenField_=ctl08_HiddenField&_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d3.5.40412.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3aen-GB%3a1547e793-5b7e-48fe-8490-03a375b13a33%3ade1feab2%3af9cec9bc%3aca57ef3c%3aab09e3fe" type="text/javascript"></script>
<script type="text/javascript">
Is there any way that I can serve them from Ajax CDN? I am on .net 4. thanks!
EDIT :
here how it looks like after I added EnableCdn property;
<script src="http://ajax.microsoft.com/ajax/4.0/1/WebForms.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/4.0/1/WebUIValidation.js" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=5-e4xi7M2z7nkjzlbU8-TWOpW3pG-5yWTc1gjU27ASzLUO3z3X6ekk3Sni1yPjhQTHZqsYZzKxrYCi_Gka_qck67rCoY74phG4J0hnrafob5PPfGsqMiXsHm5iwUWoAf11fyGw2&t=ffffffffbd2983fc" type="text/javascript"></script>
<script src="/ScriptResource.axd?d=QuFbQ1DExlSpNLIb-yKHF9rpmtXEsaZy3mY1kUywoGagqJwlk39ehRy6UMfloAvfPq5iKspCQd3hr6z2WtLRfs2vX5cK8IhsLTmXS2C608YECG519GPA63CN6_5IYjb9Or0HIg2&t=ffffffffbd2983fc" type="text/javascript"></script>
<script src="/default.aspx?_TSM_HiddenField_=ctl08_HiddenField&_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d4.1.40412.0%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3aen-GB%3aacfc7575-cdee-46af-964f-5d85d9cdcf92%3ade1feab2%3af9cec9bc%3aca57ef3c%3aab09e3fe" type="text/javascript"></script>
<script type="text/javascript">

If you're using the .NET 4 version of the Control Toolkit, simply set EnableCdn to true:
<ajaxToolkit:ToolkitScriptManager runat="server" EnableCdn="true" />

This is not possible, the control points to local dynamic files only.
Maybe a better idea is migrate the functions used, to a jquery based alternative with witch you can use a CDN.

Related

How can I make my JS script calls in Magento appear on one line?

I am doing various modifications to my NGINX Magento server and part of this is to do front end optimisations
I am currently using a CDN plugin to host my JS but Magento always calls JS lines (huge massive calls to JS libariries which looks ugly in the code view) that I want to combine to one line.
I know you can use Admin > Developer to merge JS files but I dont want to do this. I want to make this:
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/prototype/validation.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/scriptaculous/builder.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/scriptaculous/effects.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/scriptaculous/dragdrop.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/scriptaculous/controls.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/scriptaculous/slider.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/varien/js.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/varien/form.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/mage/translate.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/mage/cookies.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/varien/product.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/varien/configurable.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/calendar/calendar.js"></script>
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/calendar/calendar-setup.js"></script>
Change to
<script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/prototype/validation.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/scriptaculous/builder.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/scriptaculous/effects.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/scriptaculous/dragdrop.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/scriptaculous/controls.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/scriptaculous/slider.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/varien/js.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/varien/form.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/mage/translate.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/mage/cookies.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/varien/product.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/varien/configurable.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/calendar/calendar.js"></script><script type="text/javascript" src="http://dz36xlwnpud7z.cloudfront.net/cdn/210393/js/calendar/calendar-setup.js"></script>
I think is what you're looking for. I tested this with Magento 1.9.2.1.
In this file Mage_Page_Block_Html_Head, function getCssJsHtml() on line 210 character 112-119 you'll find this . "\n". Remove that from the function and your JS files will be rendered in one line as you requested.
Keep in mind not to modify core files but to extend the class and override only this function to maintain rest of functionality.

conflict beetween mootols and ajax script

I am not expert programmer and I need an help.
I have a conflict between these codes:
<script type="text/javascript" src="mootools-1.5.1-core.js"></script>
<script src="src/tooltip.js" type="text/javascript"></script>
the tooltip.js code is in this package:
http://www.menucool.com/download/tooltip.zip
In the project I will need use the jquery also.
Thank you in advance for your help.
A.
If using jQuery and mooTools is a must, you can run jQuery in noConflict mode. The order of the scripts should look like this to work:
<script src"path/to/jquery.js" type="text/javascript"></script>
<script src="src/tooltip.js" type="text/javascript"></script>
<!-- this will make jQuery available through the jQuery variable -->
<script type="text/javascript">$.noConflict();</script>
<script type="text/javascript" src="mootools-1.5.1-core.js"></script>

What is the correct sequence of including jquery files?

Today i wanted to add datepicker() to my page.So I downloaded jqueryui and added then in the sequence below.
<script type="text/javascript" src="js/jquery.js"></script>
<script src="js/superfish.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/retina.min.js"></script>
<script src="assets/validate.js"></script>
<script src="js/jquery.placeholder.js"></script>
<script src="js/functions.js"></script>
<script src="js/wizard_func.js"></script>
<script src="check_radio/jquery.icheck.js"></script>
<script type="text/javascript" src="js/navi_artstyle.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/mapmarker.jquery.js"></script>
<script type="text/javascript" src="js/mapmarker_func.jquery.js"></script>
It didn't work. It took me whole day to figure out what is wrong. it was the SEQUENCE of js files included!!! To work my code i had to include them like bellow.("jquery.js" position had to change)
<script src="js/superfish.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/retina.min.js"></script>
<script src="assets/validate.js"></script>
<script src="js/jquery.placeholder.js"></script>
<script src="js/functions.js"></script>
<script src="js/wizard_func.js"></script>
<script src="check_radio/jquery.icheck.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/navi_artstyle.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/mapmarker.jquery.js"></script>
<script type="text/javascript" src="js/mapmarker_func.jquery.js"></script>
Can some one explain this please. Please give me a Source so I wont make this mistake again.
Normal jQuery (core)
jQuery migrate if you have
jQuery UI
jQuery mobile
Scripts that need jQuery / scripts that are jQuery plugins
Other scripts like bootstrap
You own scripts depending which is needed first
First you have to include normal jQuery library.After that You have to include other jquery library like jquery ui and jquery mobile and all finally you have to include your own javascript files.
As mentioned in comments you have to mention the scripts in the order you use that.
Simply anything used Jquery will goes after jQuery, anything that depends on jQuery UI goes after jQuery UI etc.

Trying to understand how scripts should be added and in what order - experiencing difficulties

I'm having some difficulties with what seems to be an issue with the order that I import the JS src.
I'm pretty new to JS / jQuery so for the most part have taken for granted that I only needed to include one script and all has been working fine.
I have a contact page, on the page there is a google map and form, the form also relies on som JS to pretty it up and to validate inputs.
These were working fine.
I've now just updated the login box that will be in the header, the dropdown uses a simple jquery function to display it when selected.
Now that I have this script in place I cannot get them all to work together, I've tried various combinations but none work so I must be missing something that's important, could someone please explain?
These are examples:
The map always displays and the login function is contained within the "helperFunctions" whilst the form function calls are within "ourContactForm"
1 :
The form displays correctly, the login will not work
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/map.js"></script>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <!--Disable zoom to pinch-->
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/helperFunctions.js"></script>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("jquery", "1.3.2");
</script>
<script type="text/javascript" src="js/jquery.jqtransform.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript" src="js/ourContactForm.js"></script>
2 :
Form doesn't display how it should yet the login does
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/map.js"></script>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <!--Disable zoom to pinch-->
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load("jquery", "1.3.2");
</script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/helperFunctions.js"></script>
<script type="text/javascript" src="js/jquery.jqtransform.js"></script>
<script type="text/javascript" src="js/jquery.validate.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript" src="js/ourContactForm.js"></script>
other permutations result is not a great deal of anything working.
Thanks for your help
EDIT: using the details on jquery documentation solved :)
http://jquery.com/download/
In both examples You include both jQuery 1.3.2 and the latest one. Why? I guess, that Your plugins work with other version of jQuery. Just check it and include only one.
For anyone stumbling across this that made the same dumb mistake...
These:
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
taken from http://jquery.com/download/
will solve the issue.

<script> tag doesn't close properly

In my default.jspx which contains the basic layout for the page I am trying to import some jquery libraries as follows
<head>
...
<spring:url value="/resources/js/lib/jquery-1.9.1.min.js" var="jquery_url" />
<spring:url value="/resources/js/lib/jquery.tokeninput.js" var="jquery_tokeninput_url" />
<script src="${jquery_url}" type="text/javascript"></script>
<script src="${jquery_tokeninput_url}" type="text/javascript"></script>
<script type="text/javascript">
$.noConflict();
</script>
<util:load-scripts />
...
</head>
but when the page is rendered in the browser the first script tag swallows the two others
<head>
...
<script type="text/javascript" src="/roo-inari/resources/js/lib/jquery-1.9.1.min.js">
//These lines are inside the first script tag
<script type="text/javascript" src="/roo-inari/resources/js/lib/jquery.tokeninput.js"/>
<script type="text/javascript">
$.noConflict();
//The tag is closed here
</script>
<link href="/roo-inari/resources/dijit/themes/tundra/tundra.css" type="text/css" rel="stylesheet">
...
Any idea what might be causing this? The project is based on a spring roo generated web mvc scaffold.
I am using Chrome v.25.
The simple solution was to write a comment inside the tag so that it is not closed automatically. Silly me
<script src="${jquery_url}" type="text/javascript"><!-- required for some browsers --></script>

Categories