ASP.NET Release jQuery Included Twice? - javascript

So, I have an ASP.NET project, and in Debug mode, I get the following line in my HTML source:
<script src="/Scripts/jquery-2.2.4.js"></script>
However, when I deploy the project, my site has the following line in the source:
<script src="/bundles/jquery?v=Ww-VxqepLI91N7FDR1JXgRvM347mWv5Bv_0D4LsyGEk1"></script>
I assume this has to do with the bundling/minification. This is normal. What is not normal is that even though I'm trying to use jQuery 2.2.4, the bundled/minified jQuery source seems to contain both jQuery 2.2.4 and 3.0.0 (I verified this by opening the page and noticing multiple copies of the same functions, including the version number). As such, my site's JavaScript is failing, saying that Bootstrap requires jQuery >= 1.9.1 and < 3.0.0.
For the life of me, I can't figure out where this additional jQuery file is coming from.
References.js:
/// <autosync enabled="true" />
/// <reference path="bootstrap.min.js" />
/// <reference path="jquery.validate.min.js" />
/// <reference path="jquery.validate.unobtrusive.min.js" />
/// <reference path="jquery-2.2.4.min.js" />
/// <reference path="modernizr-2.8.3.js" />
/// <reference path="respond.matchmedia.addlistener.min.js" />
/// <reference path="respond.min.js" />
NuGet (limited to jQuery results):
jQuery v2.2.4
No dependencies.
jQuery.Validation v1.15.0
jQuery (>= 1.4.4)
Microsoft.jQuery.Unobtrusive.Validation v3.2.3
jQuery (>= 1.8.0)
jQuery.Validation (>= 1.8.0)
packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Antlr" version="3.5.0.2" targetFramework="net46" />
<package id="bootstrap" version="3.3.6.1" targetFramework="net46" />
<package id="EntityFramework" version="6.1.3" targetFramework="net46" />
<package id="jQuery" version="2.2.4" targetFramework="net46" />
<package id="jQuery.Validation" version="1.15.0" targetFramework="net46" />
<package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net46" />
<package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net46" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net46" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.1" targetFramework="net46" />
<package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.3" targetFramework="net46" />
<package id="Microsoft.Net.Compilers" version="1.3.2" targetFramework="net46" developmentDependency="true" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net46" />
<package id="Modernizr" version="2.8.3" targetFramework="net46" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net46" />
<package id="Respond" version="1.4.2" targetFramework="net46" />
<package id="WebGrease" version="1.6.0" targetFramework="net46" />
</packages>
As far as I can tell, all of the dependencies are satisfied. I guess it's possible that one of these packages is trying to include jQuery 3.
Any help would be appreciated. I've tried uninstalling and reinstalling jQuery and related libraries a few times. If any other information is necessary, just let me know!
Edit:
The result of disabling bundling is as follows. The HTML page now has:
<script src="/Scripts/modernizr-2.6.2.js"></script>
<script src="/Scripts/modernizr-2.8.3.js"></script>
... and ...
<script src="/Scripts/jquery-1.10.2.js"></script>
<script src="/Scripts/jquery-2.2.4.js"></script>
<script src="/Scripts/jquery-3.0.0.js"></script>
Any ideas what is causing this?

I solved the issue by changing my publish settings to:
Remove additional files at destination (probably the real solution)
Precompile during publishing
It's annoying that other files would be included even though the project settings don't really reference them. I guess bundles.Add was including all jquery/modernizr files matching the wildcard/"version" pattern.

Related

Custom Cordova plugin iOS index.js dosent recognise my .js file

I have written a custom Cordova plugin that brings have as a dependency "Media" plugin.
When i run "cordova plugin add "myPlugin"" the plugin is installed to the sample project however when in my index.js i try to init my plugin it does not recognise it and if i try to create "Media" object it does.
Here is my plugin .xml file :
<?xml version="1.0" encoding="utf-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="cordova-plugin-MyPlugin"
version="1.0.0">
<name> MyPlugin </name>
<description>Cordova MyPlugin Plugin</description>
<author> MyPlugin </author>
<license>MIT</license>
<keywords> MyPlugin </keywords>
<dependency id="org.apache.cordova.media"/>
<js-module src="www/MyPlugin.js" name="MyPlugin">
<clobbers target="window.plugins.MyPlugin" />
</js-module>
<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="MyPlugin">
<param name="ios-package" value="CDVMyPlugin" />
</feature>
</config-file>
<!-- Sources -->
<header-file src="src/ios/CDVMyPlugin.h"/>
<source-file src="src/ios/CDVMyPlugin.m"/>
<!-- iOS Frameworks -->
<framework src="libz.dylib" />
</platform>
</plugin>
Thanks for the help.
The problem apparently was in my "MyPlugin.js" file at the bottom of the file the line :
module.exports = MyPlugin;
Needs to be added then in the Index.js file (or the file of your choosing) add the following :
//Get a reference to the custom .JS file.
myCustomPlugin = cordova.require("cordova-plugin-MyPlugin.MyPlugin");
myPluginInstance = new myCustomPlugin(someParams,onSuccess,onError,null);
Now you can access the methods of your .JS file.
Credit to https://stackexchange.com/users/366553/marat-strelets for helping with the solution.

Exclude directory and js minification with Ant

I want to use ant for js and css minification at time of building the project. Please find below directory structure of my project:
Here, scripts directory has multiple directories.
I want to exclude directory named "Libraries" in scripts dirctory from ant task.
The dirctories other than "Libraries" has js files. And I want to include these js files in ant minification task.
Please find below my build.xml:
<project name="ITV" default="doMinification">
<property name="webroot.dir" value="webapp/" />
<target name="doMinification" depends="minifyjs" />
<tstamp>
<format property="TODAY_MY" pattern="yyyyMMdd-HHmmss" locale="en,UK" />
</tstamp>
<!-- Minify JS -->
<target name="minifyjs">
<apply executable="java" parallel="false" dest="webapp/scripts/" verbose="true">
<fileset id="jsFiles" dir="webapp/scripts/">
<exclude name="webapp/scripts/Libraries/" />
<include name="**/*.js"/>
</fileset>
<arg line="-jar"/>
<arg path="yuicompressor-2.4.7.jar"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="**/*.js" to="*-min-${TODAY_MY}.js" />
<targetfile/>
</apply>
</target>
</project>
How to exclude a specific directory and include other directories with its files in ant javascript minification task ?
You may want to check similar question here
There is this answer:
<exclude name="**/dir_name_to_exclude/**" />
For your case:
<exclude name="**/Libraries/**" />
eg:
<target name="minifyjs">
<apply executable="java" parallel="false" dest="webapp/scripts/" verbose="true">
<fileset id="jsFiles" dir="webapp/scripts/">
<exclude name="**/Libraries/**" />
<include name="**/*.js"/>
</fileset>
<arg line="-jar"/>
<arg path="yuicompressor-2.4.7.jar"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="**/*.js" to="*-min-${TODAY_MY}.js" />
<targetfile/>
</apply>
</target>
I hope this helps.

Can't build JavaScript universal Windows app

I have started a new project - javascript - windows universal app and without changing anything or adding any code I try to build it and run it but it wont with the following error:
Error : DEP0700 : Registration of the app failed. error 0x80080204: App manifest validation error: The document root element m:Package must be defined in the http://schemas.microsoft.com/appx/2010/manifest namespace. (0x80080204) App7
A similar issue was reported here and I tried renewing the license with project -> store -> aquire developer license to no avail. It seems to be that the actual problem has to be the document root element part which I'm not really familiar with as I haven't worked with Visual Studio before I tried to add xmlns:m="http://schemas.microsoft.com/appx/2010/manifest" to my package appxmanifest but that doesn't seem to have helped.
Heres the whole manifest:
<?xml version="1.0" encoding="utf-8"?>
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:m="http://schemas.microsoft.com/appx/2010/manifest"
IgnorableNamespaces="uap mp m">
<Identity
Name="155dc546-80c7-4275-b2a6-a2aa8ddec5f7"
Version="1.0.0.0"
Publisher="CN=FroboZ" />
<mp:PhoneIdentity PhoneProductId="155dc546-80c7-4275-b2a6-a2aa8ddec5f7" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>App7</DisplayName>
<PublisherDisplayName>FroboZ</PublisherDisplayName>
<Logo>images\storelogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.10069.0" MaxVersionTested="10.0.10069.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application
Id="App"
StartPage="default.html">
<uap:VisualElements
DisplayName="App7"
Description="App7"
BackgroundColor="#464646"
Square150x150Logo="images\Logo.png"
Square44x44Logo="images\SmallLogo.png">
<uap:SplashScreen Image="images\splashscreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
</Capabilities>
</Package>
Thank you for taking your time to read my question and even more so if you can help me with this problem!
Developer mode wasn't turned on in windows 10. I'm not sure what difference this makes but after turning this on I was able to build the project.

Using jQuery with WebMatrix

I have written an html file using jQuery to read a JSON file. It works fine by itself; I tested it using Safari. However, when I try to use the exact same code in WebMatrix, it gives me an error, saying the JSON file cannot be found. I checked and the file is there.
Here is a simple version of the offending code. (The same comments apply: it works by itself in Safari but says "file not found" when used in WebMatrix.)
Can someone help me?
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
var Email=new Array();
var i=0;
var email;
$.getJSON('MoodMinder.json', function(data) {
$.each(data.User, function(i, f) {
Email[i]=f.Email;
i++;
})
email="<p>" + Email[0] + "</p>";
$(email).appendTo("#email");
});
</script>
</head>
<body>
<div id="email"></div>
</body>
</html>
Here is the JSON:
{
"User":[
{"Email":"cklann999#gmail.com"}
]
}
And here is the Web.config file (added section recommended by Nidzix):
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<customErrors mode="Off"></customErrors>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add invariant="System.Data.SqlServerCe.4.0" name="Microsoft® SQL Server® Compact 4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json"></mimeMap>
</staticContent>
</system.webServer>
</configuration>
You have to have configuration file called Web.config in the root folder, containing this piece fo code:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>

Getting Data under Complex Namespaces in Javascript

I have the following XML that I need to be able to pull specific fields from:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
<id>Cases</id>
<title type="text">CaseList</title>
<updated>2013-04-04T15:32:56Z</updated>
<author>
<name/>
</author>
<link href="CaseList" rel="self" title="CaseList"/>
<entry>
<id>291</id>
<title type="text">CaseList('291')</title>
<updated>2013-04-04T15:32:56Z</updated>
<category term="S.Cases" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<content type="application/xml">
<m:properties>
<d:case_id>291</d:case_id>
<d:case_title>Global Case</d:case_title>
<d:case_type>Meso</d:case_type>
</m:properties>
</content>
</entry>
<entry>
<id>291</id>
<title type="text">CaseList('292')</title>
<updated>2013-04-04T15:38:56Z</updated>
<category term="S.Cases" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<content type="application/xml">
<m:properties>
<d:case_id>292</d:case_id>
<d:case_title>Global Case 2</d:case_title>
<d:case_type>Meso 2</d:case_type>
</m:properties>
</content>
</entry>
</feed>
I've tried almost everything, but I feel that there is a core XML concept I'm missing that would help me extract nodes such as d:case_id. Is there a simple way of pulling out one or more nodes using Javascript? The other namespace questions don't include a namespace within another namespace... here, the values I'm interested in are behind m:properties.
I have used this
parentNode.getElementsByTagNameNS("*", "name");
and it worked fine for me in chrome and IE10 browser.
Please follow the below link for details:
jQuery XML parsing with namespaces

Categories

Resources