Using resource file in html

Use external file or resource?

The end result is that your file(s) get embedded in your DLL so that you only have 1 DLL to distribute instead of a DLL and a folder of files that have to move around together. That said, you haven’t said how large these files are.

Use external file or resource?

I am writing a C# application that uses a long «hard-coded» string.

For maintainability reasons I have decided to put this string in an external text file and load it. Is this a good idea? The extra I/O does not seem big in this case.

I realize that I also have an option to embed this file as a .resx resource. Is this a better idea? The file will never need to be localized.

If you intend to allow users/administrators to change the string, I agree with the other answers, and I’d suggest putting it in settings.

If you don’t want it to be editable after deployment and it will only be modified by you and your developers, then I would put it in an embedded resource (note, this is not the same as a .resx file). You would read it at runtime like this:

Assembly assembly = Assembly.GetExecutingAssembly(); Stream stream = assembly.GetManifestResourceStream(“MyAssemblyNamespace.MyTextFile.txt”); StreamReader reader = new StreamReader(stream); string theText = streamReader.ReadToEnd(); 

Update: This is solution that is easy to maintain. The .txt file will just be another file in your solution explorer in Visual Studio and you can edit it just like any other file, keep it under source control like any other file, etc. To turn it into an embedded resource by changing the Build Action in the properties window to «Embedded Resource».

The end result is that your file(s) get embedded in your DLL so that you only have 1 DLL to distribute instead of a DLL and a folder of files that have to move around together.

Update 2: Regarding «production debugging», this is a very static solution, and so you won’t be able to change the contents of the text file at runtime because the file is baked into the DLL at compile time. For reading the contents of the file, you can use tools like reflector to view the embedded resources of a DLL. You could also write a simple command line tool that dumps all the embedded .txt files from a DLL into individual files for you to look at.

For memory usage, there isn’t a solution more efficient than «I load it from a file into memory only exactly when it is needed». You have to decide whether the improved maintainability and deployment is worth the cost of a little extra memory when your DLL is loaded into memory for your specific situation. That said, you haven’t said how large these files are. If they are really huge (megabytes+), I would probably not use this solution and would go with loose files on the hard drive. If they are generally pretty small (hundreds of kilobytes), I wouldn’t worry about the extra memory unless you are in some kind of embedded device situation where RAM is really tight.

Читайте также:  My First Webpage

Why not make it an appSetting in your web/app.config file?

using System.Configuration; //To ease your typing pains var myReallyLongString = ConfigurationManager.AppSettings["MyLongString"]; 

You can follow this MSDN link how to use Application and User Settings.

I would put this in an application configuration file.

Scope on extension resource types, Apply at deployment scope. To apply an extension resource type at the target deployment scope, you add the resource to your template, as would with any resource type. The available scopes are resource group, subscription, management group, and tenant. The deployment scope must support the …

Why should I put external resources in the html head?

I really like to know why people say «put external resorces on the head of the page», such as :

Is it not better to add these resources to the page only if it needs those resources? For example, when programming on PHP, if I have a page that needs some CSS instead of other that don’t need it, will it be more intelligent to use link type or script src into that page, without loading everything in the top, isn’t it?

I see many suggestions on forum/community that say to put ALL in the head. what can you say?

The reason to use external resources, even if they include directives that aren’t used on the current page, is to take advantage of HTTP and browser caching. The resource is only sent to the browser once, on first request. This is especially important for mobile devices as there is a great deal of overhead in sending additional resources over HTTP when using limited bandwidth.

You should put external JavaScript last in the page body, not the HTML head.

There are two things here, and I’m not sure which you are asking about.

Saying they should be in the can mean as opposed to elsewhere in the document. Some people do put CSS links in the body, even though they aren’t allowed there, and also while is allowed in the body, it’s almost always a better idea to put it in the head (and those cases where it isn’t should be obvious, and even though can often be re-written to work better from the head, with the exception of cut-and-paste scripts relating to other services, where e.g. amazon give you a script to put in your page that they want to make simple for you, rather than requiring serious re-writing of your code).

As for whether it should only be in those pages that need them, there is a balance here.

Firstly, let’s say that 90% of a CSS stylesheet’s declarations are used on all pages in a site (this is a sign of a well thought-out style in itself). We could put the other 10% in separate files for some pages only, and indeed more likely 2% in one, 3% in another and 5% in yet another or something like that. However, since each URI access has its own overhead on top of the bandwidth of the actual stream downloaded, we probably lose more than we gain here.

Читайте также:  Typing Text Animation

Add in the effect of caching, and keeping it in one file is a clear winner.

On the other hand, say there are a set of resources in a site that have very different styling needs to the others. In this case the separate CSS might be as large or larger than the first one, so it makes more sense to have that as a separate file only used where necessary (also, it can make over-riding in the cascade work much better, e.g. if the «main» stylesheet gives a blue background then the second can give a red background and we indicate which we need simply by whether that stylesheet is there or not, without having to set different classes throughout the relevant HTML pages).

The same applies to javascript, a couple of functions used only rarely should probably still be in the «common» javascript files, but a large set of functions for use only in one page should almost certainly only be loaded in that one page.

That said, we may choose to include the second js in a relatively light page that is likely to be hit before a relatively heavy page that will use it, just to take advantage of the caching. This latter I would consider more an optimisation of the site as a whole, than a concern of the design of that one page (considered as an individual page, the second js is clearly wasteful).

Finally, it’s just simpler to have a single file handling all of these items, and the waste in a few extra downloads may be justified by the reduced maintenance.

If your page only contains PHP, there is no need for external resources. (= no head, no doctype clarification, no tags)

If it does contain minor or major HTML (or any other markup for that matter) it is highly adviced to use external resources.

For your javascript it’s a best practice to put all your tag in the bottom of the page just before just tag. By doing that you make sure that all you page is loaded when your javascript begin to load, so it doesn’t slow your page and make your visitors leave.

For CSS I generaly put my tag on the when I have only one CSS for all my pages. But if you have specifics CSS files for some pages you can use the same tecnhnic than javascript.

CREATE EXTERNAL DATA SOURCE (Transact-SQL), To create an external data source that references a named instance of SQL Server, use CONNECTION_OPTIONS to specify the instance name. First, create the database scoped credential, storing credentials for a SQL authenticated login. The SQL ODBC Connector for PolyBase only supports basic authentication.

What is a list of HTML elements that load external resources? (HTML Email)

I’m looking for a list of elements that can load external resources given no additional DOM manipulation via JavaScript is allowed. I am trying to host e-mails from third parties with an HTML viewer and when that happens, I need to remove any resources that load automatically so that only the base HTML is displayed even if that makes the content show up incorrectly.

Читайте также:  My New Webpage

Are there any other elements or patterns I need to take into account to prevent third-party resources from being loaded. And, yes, I am familiar with the sandbox attribute, but we require support for older browsers as well.

has universal support and is the standard for referencing external images in email. Images can also be displayed in using url:www.website.com/image.jpg .

has decent support for referencing things like webfonts and external stylesheets.

, , and are supported by a few clients, but not many.

is another that has some support that’s worth watching out for.

I don’t believe or are supported in email clients. they’re generally stripped from any markup.

Create a resource pool — SQL Server Machine Learning, To provide more fine-grained control over which workloads should have precedence, you can create a new user-defined external resource pool. Define a classification function and assign it to the external resource pool. The EXTERNAL keyword is new. Create a new user-defined external resource pool. In the …

How to load external resources using a reference URI in Java XML

I am trying to extract an XML node from a URI reference. This URI reference is generated by an XAdES4j signer, and could reference a node within the same XML file, or in the same folder.

I was hoping that loading the reference would be as simple as

XMLSignatureInput referencedXML = ResourceResolver.resolveStatic(referenceNode.getAttributeNode("URI"), referenceDoc.getBaseURI()); 

However this just gives me a NullPointerException with no useful message. Both arguments are non-null, and in a simple case the URI attribute was «data.xml» and the referenceDoc base URI was «/Users/ryan/. /test-files/signature.xml. data.xml resides in the same test-files directory.

The URI could point to an element within a file, so I’m hoping there is a reference loader which deals with that complexity for me. What have I missed?!

The reference I am trying to load is:

Total stab in the dark (you really need to paste stacktraces. ), but here goes.

I took a quick look at the source of ResourceResolver at: http://java2s.com/Open-Source/Java-Document/XML/xml-security-1.4.3/org/apache/xml/security/utils/resolver/ResourceResolver.java.htm

I can see there is going to be a NullPointerException due to a non initialised _resolverVector field in the ResourceResolver, unless the static init() method has already been called on ResourceResolver. Above the init() method, there is a comment:

The init() function is called by org.apache.xml.security.Init.init() 

The ResourceResolver itself does not appear to trigger that call — do you do it ? If not you should try it, prior to using any of the org.apache.xml.security stuff.

Firstly you need to understand what exactly is causing the NullPointerException so I would suggest splitting this code out so that you can see where the null value is.

Debugging External Sources with Visual Studio, Follow the settings checklist below to make sure modules can appear in Solution Explorer’s “External Sources” node. In the Tools -> Options -> Debugging options. Disable Just My Code: This will allow the debugger to attempt to locate symbols for code outside your solution. In the Tools -> Options > …

Источник

Оцените статью