I've created a Flex application and the size of the swf file is ~900KB.
My trouble is that the files are not getting cached. When I launch the application for the second time, the swf file is fetched again from the server.
I'm including the swf file in a jsp, and I'm not modifying any HTTP Caching Headers. I assumed that the swf files will be cached automatically. Isn't it so?
How do I forcefully cache the file? Do I need to provide anything in the MXML code or just a response.setHeader("Cache-Control","max-age=100"); is enough? Can anything be done from the flex side itself?
Suggestions please...
I presume you mean that your JSP page generates HTML which contains a reference to the SWF - this would be the common case. In this case, there are (at least) two HTTP requests made by the browser - one for the JSP page and one for the SWF file. As the SWF file is static, it may be served up by your J2EE server or by your webserver (e.g. Apache), depending on your configuration. You will need to check what cache settings are applicable to your static content (e.g. images) and ensure that those settings prevent caching of the SWF. Your JSP cache settings will only affect the HTML and not the SWF.
Ideally, browse your site using Firefox and Firebug and check the headers for each HTTP request (Firebug's Net tab). This should give you the information you need about what headers are applicable to the SWF.
I would assume that the request for the SWF is separate from the request for your JSP page (just like requests for images are separate). Thus, you probably need to configure your server to serve SWF files with a specific cache header. I doubt changing the cache settings for the JSP page will make a difference.
Related
I have way too many pages in the application that basically load the same set of xml and js files for client side interaction and validation. So, I have about dozen lines like this one <script type="text/javascript" src="JS/CreateMR.js"></script> or like this one <xml id="DefaultDataIslands" src="../XMLData/DataIslands.xml">.
These same files are included in every page and as such browser sends request to read them every time. It takes about 900ms just to load these files.
I am trying to find a way to load them on just the login page, and then use that temp file as source. Is it possible to do so? If yes, how and where should I start?
P.S. A link to a tutorial will work too, as I have currently no knowledge about that.
Edit:
I can't cache the whole page, because the pages are generated at runtime based on the different possible view modes. I can only cache the js and xml file. Caching everything might be a problem.
Anyway, I am reading through the articles suggested to figure out how to do it. So, I may not be able to accept any answer right away, while I finish reading and try to implement it in one page.
Edit:
Turns out caching is already enabled, it is just that my server is acting crazy. Check the screenshot below.
With Cache
Without cache
As you see, with cache, it is actually taking more time to process some of the requests. I have no idea what that problem is, but I guess I should go to the server stack exchange to figure this out.
As for the actual problem, turns out I don't have to do anything to enable caching of xml and js files. Had no idea browsers automatically cache js files without using specific tag.
Totally possible and in fact recommended.
Browsers cache content that have been sent down with appropriate HTTP caching headers and will not request it again until the cache has expired. This will make your pages faster and more responsive and your server's load much lighter.
Here is a good read to get you started.
Here is ASP.NET MVC caching guide. It focuses on caching content returned from controllers.
Here is a read about caching static content on IIS with ASP.NET MVC.
Basically, you want to use browser caching mechanism to cache the src files after the first request.
If you're using F12 tools in your browser to debug network requests, make sure you have disable cache option unchecked. Otherwise, it forces browser to ignore cached files.
Make sure your server sends and respects cache headers - it should return HTTP status 304 Unmodified after first request to a static file.
Take a look at Asp.Net Bundling and minification - if you have for example multiple js source files, you could bundle them into one file that will be cached on the first request.
Additionally, if you use external js libraries, you could download them from a CDN instead of your server - this will both offload your server and enable user browser to use cached script version (meaning - if some other page that user has visited also used the same script, browser should already have it cached).
One approach is caching static files via IIS by adding <clientCache> element in web.config file. The <clientCache> element of the <staticContent> element specifies cache-related HTTP headers that IIS and later sends to Web clients, which control how Web clients and proxy servers will cache the content that IIS and later returns.
How to configure static content cache per folder and extension in IIS7?
Client Cache
for more info on client side caching read this part of Ultra-Fast ASP.NET 4.5 book:
Browser Cache and Caching Static Content
Other approach is caching portions of page.
if your are using Web Form:
Caching Portions of an ASP.NET Page
and if you are using MVC, use Donut Hole Caching
ASP.NET MVC Extensible Donut Caching
Donut Caching and Donut Hole Caching with Asp.Net MVC
The browser has to ask the server if the file has been modified or not since it put it to the cache, therefore the http statuscode 304. Read more from https://httpstatuses.com/304.
As this is asp.net please make sure you are first running it with
<compilation debug="false"/>
as enabling debugging has some side effects which include.
"All client-javascript libraries and static images that are deployed via
WebResources.axd will be continually downloaded by clients on each page
view request and not cached locally within the browser."
More read from https://blogs.msdn.microsoft.com/prashant_upadhyay/2011/07/14/why-debugfalse-in-asp-net-applications-in-production-environment/
How can I make sure that static content (images, css, javascript) is cached? What is the best approach?
Will recommend you to go through this tutorial to understand how caching happens on web (HTTP) in general.
Simply speaking, the web server needs to generate appropriate HTTP headers while sending the content to the client in order to control client-side caching. In ASP.NET/IIS environment, its IIS that typically handles the static file contents and therefore, you must configure IIS appropriately to control caching static files as per you needs. See below links for more information about configuring IIS caching for static content:
http://www.iis.net/ConfigReference/system.webServer/staticContent/clientCache
How to configure static content cache per folder and extension in IIS7?
EDIT: As you have asked about the best approach, the most prevalent approach that I see now days is to version static content (say by appending some version identifier at the end of file or URL). Once version-ed, you can treat it as immutable and then emit cache headers for caching it for infinite duration. In ASP.NET application, you can probably append the assembly version (or product version) to each static content URL. So essentially, you will invalidating the cache for every build (or every product release).
You can also make use of the HTML5 Offline web applications manifest. It allows you to set up a manifest where you define which files will be cached locally.
It is a nice, clear to understand broadly implemented, way of avoiding having to learn about IIS and HTML Caching.
http://www.w3schools.com/html/html5_app_cache.asp
(you should totally read up about those things)
Does Adobe Flex support caching of the main application; i.e. if the user had previously loaded it and it hasn't been modified since last loaded, can the browser get the swf file etc. from it's cache? I'm on an embedded system with boa as the web server, so can modify any behavior there as needed.
Thanks,
Fred
Not sure if the actually is an answer to your question, but I can tell you that the browsers will cache the swf files as long as it is referenced the same way within your html.
Ie. we use src="myApp.swf?dummy=102032" when referencing to it to avoid caching. You can use httpfox or any other networking monitor tool to see when your swf is cached.
The browser does the caching automatically just like any other file you view through it. As long as the user has a cache setup in the browser, there shouldn't be a problem unless the URL to the file changes (that includes query strings).
There is also RSL caching, if you are using RSLs. By default, they are just in your output folder as SWFs, but you can use the Adobe signed RSLs which are of the SWZ extension, are hosted on the Adobe site, and are cached at the Flash Player level, not the browser. This means that even if a user has caching disabled in the browser, it will cache the RSL either way.
I couldn't find a way to control how Glassfish (v3) handles HTTP(s) headers it sends whenever I request a resource (image, css...). The problem is that inside a security-enabled web application it forces a 0 expiry date for everything (even images and css), which makes the whole application feel like a slow and buggy piece of junk by forcing the reload of every image (IE is especially sensitive for this).
I could work around this by putting the image resources in another WAR, or even a separate directory on the server, but that would defeat the point of easy (re)deployment of an EAR file.
I also have a requirement that the files MUST come through an HTTPS connection. Does it cause any problems with certificates etc. if the image context path is different from the application context path (eg. the application is at https://foo.bar.org/sm/MyApp, and the images are at https://foo.bar.org/img)?
Well, I implemented my own resource Servlet, and finally.... it works!
I'm still interested in the Glassfish solution though.
Around 90% of the pages for our websites have no .Net code embedded in them yet are published as .aspx files. I want these to render as fast as possible so I'm removing as much as I can.
Does the .Net page directive have an impact on performance? I am thinking about two factors; the page speed for each GET and what happens when the file changes. The CMS system re-creates each page daily and I'm wondering if this triggers the ASP.Net compilation process.
If your pages have no .NET code and rendering speed is your goal, you may wish to consider changing the extension to .html. Any .aspx page will be passed to the .NET ISAPI filter by IIS and go through the entire chain of HttpModules, then will be handled by the Page HttpHandler. Using a .html extension would trigger IIS to process the request using the Static Resource ISAPI filter, which has a much shorter pipeline and is tuned for resources that run no code.
The <%# Page %> directive is not required. Without it, the default values for Language and other stuff will be assumed.
By changing a .aspx file, it'll be recompiled (it doesn't recompile the whole app though):
Any changes to a dynamically compiled file will automatically invalidate the file's cached compiled assembly and trigger recompilation of all affected resources. The next time a request to the code is made, ASP.NET recognizes that the code has changed and recompiles the affected resources of the Web application. This system enables you to quickly develop applications with a minimum of compilation processing overhead. (Note that depending on the change to the resources, the result can range from recompiling a single page to recompiling the whole Web site.)
Ok, put them in - just to be sure.
.NET pages are ALL compiled, page directive or not. nothing changes. Post compilation, they are as fast as it goes, as they turn into a class (type loaded once) that just executes.
Note that the post by Mehrdad Afshari is factually wrong (sadly I can not tag it). Any page change triggers a complete recompile AND restart of the appdomain. Acutally any FILE change does so, as long as it is outside App_Data and ASP.NET can see it (i.e. non-hidden flag on the directory / file).