Convert JavaScript file into dll file - javascript

I have a project with Visual Studio 2012 and i have Java Script files, and CSS files in this project.
I want to make all JavaScript files as DLLs and CSS files as DLLs just like my C# Code.
Is that could be done ?, And with what tool ?
And if I'm working with bundles it will still can read from it?
Any help will be appreciated, Thanks.

You can do this for JavaScript but not css using VisualStudio. You need to add your js files as Embedded resource and then reference them in your code.
this MSDN article goes into details but basically
You add the file as an embedded resource thought VS
Use ScriptManager.RegisterStartupScript to register it
Add a web resource attribute [assembly: System.Web.UI.WebResource("SampleControl.UpdatePanelAnimation.js", "application/x-javascript")]
Personally I wouldn't recommend it. It makes the JavaScript horrible to debug, it prevents client side caching and it forces you to rebuild your site if you need to change the javaScript. I'd simply add a <script> tag, like everyone's always done.
MSDN article on style sheet resources but basically it just references it using a link tag, so it's not the same as above.

Related

How to reference a TypeScript file from a web page

Preamble
I can get this to work but I'm not sure I'm using the technology as Microsoft intended.
Context
A web page can refer to a JS file containing JavaScript by means of a reference tag like this:
<script src="Scripts/jquery.js"></script>
In the above example, the JS file is part of a Visual Studio ASPX.NET project. It was both placed in the project Scripts folder and added to the project by Nuget.
Having added a Typescript file to an existing ASP.NET project, I would like to use the generated JS from an ASPX web page.
Instructing Solution Explorer to show all files reveals that the expected JS file has indeed been generated on the expected path.
Am I using this correctly? What is the recommended method?
There are a couple of ways one might go about things.
Refer directly to the generated JS file
I was concerned that files not part of a project would be excluded from a web server deployment, but have since determined that they are deployed.
Add some kind of reference to the Typescript file
It would be great if there were some syntax for a reference to the TS file that will be transformed into a script tag referring to the generated JS file. Alas, if this exists it's not very well publicised.
In VS2015, dragging the TS file onto an HTML or ASPX page in the editor will insert a link tag referring to the corresponding JS file.
DO NOT use server URL rewriting to remap references to the TS file to the JS file. This interferes with VS and browser debug support via source map files.

Automated method to add javascripts/css into local html files and execute them

I have a set of html files needed to be modified locally. So I found an easy way to do that: write javascript/css, attach them into existing html, run them in a web browser, and save the results back to html files. The problem is I have a very large set of html files to be processed. So I need an automation.
I would love to know how this task should be addressed. I found that there is an automated testing tool like Watir, but still wonder if this is the right option for the problem.
Specifically I use jQuery to easily parse and modify html pages dynamically. This is the reason I don't want to do it otherwise with, for example, Java which lacks support of good libraries for html parsing.
A "headless browser", like Phantom JS may help you.

References Asp.net JS files

I have a notepad filled with references to over 1k .js files. I would like for my page to check this file and add each as a reference eg:
<script type="text/javascript" src="####.js"></script>
any idea or examples on this.
Thanks
Not a direct answer to your question, maybe, but if you reference that many files maybe you should look at the Google closure compiler, or the Dojo build system, or search for javascript minifiers?
In addition to your page loading faster, you won't have to generate all those links.
Also not a direct answer, however you could simply create a control which is entered into your asp.net masterpage in the header and geneates your script tags.
However by itself that's going to cause serious performance problems with your website having references to so many javascript files.
I would serioulsy recommend that you look into using the AjaxToolkit (or other frameworks) to merge and minify all of your separate JS files into 1 file that gets generated dynamically.
The example I have below is for both CSS and JS which does minification and compression on the fly.
https://softwareengineering.stackexchange.com/questions/98810/how-to-organise-website-css/98818#98818

Javascript/Markup in Assembly

I'm trying to somehow render out javascript for a particular user control rather than just having a script include for the javascript file.
The reason why I don't want a simple script include is because I need to append unique ClientID's to the dom elements at runtime.
I could hardcode the javascript in a function and just append the ClientIDs. However, this will look messy and I'm not liking the idea of hardcoding javascript code in a class- it would be a nightmare to maintain.
What are some strategies that I can use to keep javascript/markup separate from the compiled code? I want to somehow have the javascript source included in the assembly as well so that as a user control, it would not require manual script includes and have no other dependencies for it to work.
I used this code from Rick Strahl's blog. Works awesome with jQuery and those types of libraries. http://www.west-wind.com/WebLog/posts/252178.aspx
HTH,
ck
PS If you're using a Web Application Project you can use javascript files as embedded resources.

Referencing Javascript libraries with Tomcat

I am using Eclipse Ganymede and Tomcat 5.5. I would like to add some javascript and especially ajax functionality to a dynamic web project and need some help.
I would like to use jquery (but I am open to other suggestions, if you tell me why another library would be better in this case, but I have chosen jquery because it is supposed to be simple (which on the first look it seems to be)).
I am having two problems:
1- Tomcat can't find the jquery library. I tried several things in my jsp file like:
<script type="text/javascript" src="WEB-INF/lib/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/WEB-INF/lib/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="./WEB-INF/lib/jquery-1.3.2.min.js"></script>
As you can see, I threw the jquery library in /WEB-INF/lib. Executing the jsp file within a browser without tomcat (with the last path version) works, so the path is correct.
2- There is no proper syntax highlighting within the dynamic web project for jquery and no popup suggestions. I also tried the information in this article, but it didn't change much.
To be more specific (because it took me about half an hour to figure this out after getting to this point):
When you create a Dynamic Web Project with Tomcat in Eclipse, among other things in the project you get a folder named "WebContent". That's the actual folder that gets deployed to the Tomcat server, in Eclipse's equivalent of Tomcat/webapps/<project name> (I'm not sure where it really exists). For security reasons, as a special case nobody can access the META-INF and WEB-INF folders in there, so putting your scripts in those places will not help.
What you have to do is create a folder inside of WebContent, and stick your Javascript in there. This folder will be globally visible, so visitors to your site (like you, when you test it) can actually get to the Javascript.
What I did, for instance, was create a folder named "script" in WebContent and put my Javascript in there; then, when I needed to reference it in a page, I put in src="ProjectName/script/AwesomesauceJavascript.js"
I'd like to add to what #Tacroy responded with. Within the server you're using in Eclipse, check the server.xml. Make sure:
Context docBase="SomeProjectName" path="/SomeProjectName" <-- path and docBase attributes need to be the same.
I had two different things there, and had to make them identical for the src attribute to work in the jsp.
First you must to add resource mapping to your folder where you put jquery.js script library. That folder must be public.
To make folder public use this line of code:
<resources mapping="/scripts/**" location="/WEB-INF/scripts/**" />
Now you just need to add reference in your page to this path:
<script type="text/javascript" src="scripts/jquery-1.10.2.js" ></script>
Below are the steps to enable jQuery syntax highlighting and content assist highlighting in Eclipse.
Download jqueryWTP0.40foEn.jar.
Find your Eclipse Plugin org.eclipse.wst.jsdt.core_version.jar, backup the plugin.
(e.g. C:\DEV\EclipseIndigo37\eclipse\plugins
\org.eclipse.wst.jsdt.core_1.1.100.v201104272153.jar)
Double click the JAR file or run with command java -jar jqueryWTP0.40foEn.jar.
On the opened swing UI, choose org.eclipse.wst.jsdt.core_version.jar, and output directory.
Click the generate button.
Replace the old org.eclipse.wst.jsdt.core_version.jar file with the generated file.
Delete the directory workspace/.metadata/.plugins/org.eclipse.wst.jsdt.core
Start Eclipse.
Open a HTML file or a JavaScript file, edit JavaScript content.
jQuery content assist is now available.
Plugin Developer & Source

Categories