Should I embed CSS / JavaScript files in a web application?

I recently started embedding JavaScript and CSS files in our shared library DLLs to simplify deployment and versioning. I'm just wondering if there is any reason why you want to do the same with the web application, or if it is always better to just leave them as regular files in the web application and use only the built-in resources for the common components?

Are there any advantages to implementing them?

+6
projects-and-solutions embedded-resource
source share
6 answers

Of course, if anyone who knew what they were doing could use the Reflector picker and retrieve JS or CSS. But that would be much more than just using something like FireBug to get this information. A typical end-user is unlikely to have the desire to address all these issues in order to spoil the resources. Anyone interested in this type of thing is likely to be a malicious user, not an end user. You probably have many other security concerns if the user can use a tool such as a build reflector in your DLL, because by that time your server was already hacked. Security was not a factor in my decision to deploy resources.

The bottom line was to get users to do something stupid with these resources, for example, delete them, thinking that they are not needed or in any other way interfere with them.

It is also much easier to pack an application for deployment purposes, since it involves fewer files.

It is true that the DLL (class library) used by the pages is larger, but this does not make the pages larger. ASP.NET creates the content that must be sent to the client (browser). Content is no longer sent to the client than is required for the page to work. I do not see how the class library that helps maintain these pages will affect the size of the data sent between the client and server.

However, Rjlopes has a point, it may be true that the browser cannot cache the embedded JavaScript / CSS resources. I have to check this, but I suspect Rjlopes is right: JavaScript / CSS files will need to be loaded every time a full-length postback is sent to the server. If this turns out to be true, this performance hit should be a factor in your decision.

I still couldn’t check the performance differences between using the built-in resources, reselling and individual files, because I was busy with my efforts. I hope that today I will take care of this because I am very curious and the caching point of the Rjlopes browser has risen.

+3
source share

I had to make the same decision once. The reason I decided to embed my JavaScript / CSS resources in my DLL was to prevent these files (by the curious end users who purchased my web application) from being spoofed after deploying the application.

I doubt and doubt the validity of Easement's comment on how browsers load JavaScript files. I am sure that the built-in JavaScript / CSS files are temporarily recreated by ASP.NET before the page is sent to the browser so that the browser can load and use them. I am interested in this, and I will run my own tests. I will let you know how this happens.

-Frinny

+4
source share

Reason for implementation: Browsers do not load JavaScript files in parallel. You have a lock condition until the file is downloaded.

Reason against implementation: you may not need all the JavaScript code. Thus, you can increase throughput / processing without the need.

+1
source share

As for the browser cache, as far as I noticed, the answer to WebRecource.axd says that "304 is not changed." So, I think they were taken from the cache.

+1
source share

I had to make the same decision once. The reason I decided to embed my JavaScript / CSS resources in my DLL was to prevent these files (by the curious end users who purchased my web application) from being spoofed after deploying the application. Reason against implementation: you may not need all the JavaScript code. Thus, you can increase throughput / processing without the need.

+1
source share

You know that if someone wants to interfere with JS or CSS, they just need to open the assembly with Reflector, go to the Resources section and edit what they want (it may take a lot more work if the assemblies are signed).

If you paste js and css into the page, you make the page larger (more KB to load for each request), and the browser cannot cache JS and CSS for the following requests. The good news is that you have fewer requests (at least 2 if you are like me and combine multiple js and css and one), plus javascripts have problems loading in serial.

-one
source share

All Articles