Liferay application adapter does not work with javascript files - javascript

I need to use application adapter to implement different functionality for different sites. If I set 'false' in liferay-hook.xml, and select appropriate adapter in liferay 'site settings' all modifications which are in jsp files are displayed but modifications in js files are not.
Any ideas how to use application adapter to customize js files per site?
Thanks a lot for your reply.

You can't. An application adapter changes the way the application server resolves JSPs - while JS files are directly requested from the browser.
As JS files are typically minified, with no notion of different files due to the site, you'll have to make your JS files aware of the different conditions in which they run - e.g. introduce conditional initialization in them or embed different JS files in your themes (or make the themes configurable to include different JS files)

Related

get fresh copy of HTML, CSS and Javascript files resources

I have an ASP.NET MVC 5 application, this application includes HTML, CSS, and Javascript files when I do some update in HTML, CSS or Javascript and deploy it in the server, to see that change I have to clear the cache in local PC.
This is a common question, but answers are not straight as I see.
So I wish to know, can I include a function to refresh the existing HTML, CSS and JS files using javascript approach. when the application load, gets the HTML, CSS and JS files as fresh copies. This is like clear the cache in the browser using javascript.
If cannot achieve this any other alternative?
Since you're using MVC 5, this can automatically be handled for JS and CSS for you, if you use bundling and minification.
The request ...
for the bundle ... contains a query string pair....
The query string ... has a value token that is a unique identifier
used for caching. As long as the bundle doesn't change, the ASP.NET
application will request the ... bundle using this token. If
any file in the bundle changes, the ASP.NET optimization framework
will generate a new token, guaranteeing that browser requests for the
bundle will get the latest bundle.
Essentially, the ASP.NET application will handle the caching of JS and CSS for you.
You can read more about how this works and how to implement it on the MSDN article for Bundling and Minification.
I'm not sure what you mean by caching HTML. If you're using a .cshtml file, it shouldn't be cached by default as far as I know. However, you can specify on your controller how long to cache the results of an action for, such as in this post:
You can use the OutputCacheAttribute to control server and/or browser
caching for specific actions or all actions in a controller.
If you provide my detail on how the HTML is being cached, I might be able to provide a more helpful answer.

AngularJs SPA Javascript file

Do i have to include all my javascript file while loading main index page?
In single page application when we are not logged in, we include all of our .js file in main index file. This contains js file that is only needed when users are logged in.
What is better approach of managing angular app in this context?
Simple answer: yes.
Your application is a single-page one, so you can combine all JS files into one and load it at one request. It saves time for processing in the future.
Alternatively, create two pages login.html and others.html, then load two different sets of JS files accordingly.
Normally, nowadays the bandwidth is not the bottleneck, loading a larger JS file does not make trouble (usually).
You can split your code into multiple modules and then just load the js needed for that module.
I suggest using Gulp with packages to inject HTML when appropriate. You then have single lines of code as place holders for your Javascript and you run the Gulp task to inject the Javascript into the areas where it is needed.
You could also run gulp tasks to minify your js into just a few minified files. You will need to be sure your js in min safe (gulp can do this too).
If you make AMD - most often using RequireJS - then you won't need to include all from the very beginning.
A while ago we did a similar project, although without AngularJS, and by using RequireJS we made the different pages, which use different files. And this way people's browsers will never download certain files if they never go to certain pages.
(Of course, we had many pages inside the app, not just 2 or 3, where this wouldn't make any difference.)

Prevent circumventing ASP.NET minification

I've got some ASP.NET that I'm deploying as an Azure cloud service. The javascript files have comments in them that I'd like not to be visible to anyone consuming the JS. I'm taking advantage of ASP.NET bundling and minification:
http://www.asp.net/mvc/overview/performance/bundling-and-minification
This seems to be a nice solution in that it removes all comments during the minifcation process. But I can't count on the fact that the user won't directly point his or her browser directly to the individual, original js files. I'm trying to figorue out how to prevent the user from pulling the js files directly (forcing them to pull only a bundle), in order to prevent viewing comments. Is there a way to implement a black list of files that can't be downloaded? If not, I was thinking of adding a series of random characters to the name of each js file. Lastly, if that doesn't seem like a good idea, I would investigate injecting something into the VS build process to strip comments on publish.
Any thoughts would be welcome.
You can use blockviewhandler in a web.config in the folder your js is in. Explicitly whitelist any files that are OK to download and then block the rest.
There's an example in this question:
Where to put view-specific javascript files in an ASP.NET MVC application?
I think you can modify your deployment process. To your production server upload only the minified js files but to your test/dev server upload everything.

How to include external Javascript in GWT offline application

I have a GWT (well, GXT) application that uses an external JavaScript library to add functionality to my app. My application must work offline, too, and herein lies my problem.
I am aware that adding files to the public folder will make them accessible by my GWT app, but this will not work in case of offline use. GWT compiles my app to make it available offline without problem, but it doesn't include the external JavaScript library.
So, whenever I work within the application and reach the point where said library is needed, the browser will attempt a GET request because the library hasn't been loaded yet and doesn't remain in the cache of the browser reliably.
Is there a way to add the library to my app so that it will be cached together with my GWT app? The library consists of several folders, JS files, images, CSS, etc. My only idea is to dynamically create an Appcache Manifest that dumps ALL files in the browser cache.. in which case I'm scared of breaking the GWT offline functionality.
Yes you can generate a manifest at compile time. Just use a linker that extends com.google.gwt.core.ext.linker.AbstractLinker.
See for example this example manifest linker
or see Writing a GWT Linker
or see this stackoverflow thread
I do that to include google fonts and to produce a manifest that will only include files for that specific language permutation.

Loading local files via jQuery (part 2)

Ok, here we discussed the essence of the problem: in some browsers like Chrome and Opera HttpRequests to local files is turned off by default.
Now the question is: how to build such HTML+javascript viewer of HTML documents, that:
would run locally on any (or most of) browser(s) without additional tuning;
would not use frames;
would have an ability to work with many different files(5-10k);
It can't be done in straight HTML/Javascript if you want to load files via Javascript using AJAX requests. There are good security reasons to not allow local files script access to other files on the local system (see my answer here for more details), so most browsers will not allow this without special user configuration.
So your options are:
Don't load files with Javascript, use frames or another mechanism. If, as you state in the other question, you're shipping all this on CD, you might want to consider using some sort of build system that allows you to create static files using templates and either a database or flat-file content - Jekyll is one option I know of.
Ship an executable along with the files that can either run a local webserver or run HTML files in an application context. I think Appcelerator Titanium might fit the bill.

Categories

Resources