inject html using apache - html

I have a portal that is under a virtual host in Apache. All lot of its .css and .js is generated dynamically by the underlying tomcat web application. What I want to do is inject some of my own .css and .js into the mix before it is served. I think I need something like mod_rewrite but for html.
I know I could try to piggyback onto some resource reference that is used on every page and use mod_rewrite that way, but that is hard to do and I need my css to be applied last.
Tell me there are some magic beans for this. I just need to inject a couple scripts and styles right at </head>.

I haven't used it before, but it looks like mod_ext_filter could do this
By looking at the example, you could try the following Perl script
#!/usr/local/bin/perl -w
use strict;
my $extraCode = "<script src=\"http:/...\"></script>";
while (<STDIN>) {
s/<\/head>/$extraCode<\/head>/i;
print;
}
After I posted this, I noticed someone recommended https://serverfault.com/questions/46449/how-to-inject-html-code-into-every-delivered-html-page. mod_proxy_html and mod_sed looks good

Related

Smarty - include file

I tried to include a tpl file using smarty include file like this,
{include file='file_name.tpl'}
its not working for me. Is it needed to include path name.
Try to set path to templates before. So call setTemplateDir before rendering of your template.
More here: https://www.smarty.net/docs/en/api.set.template.dir.tpl
Also as I can see Smarty allows to specify full path to template file inside of include directive. So even this is possible:
{include file='file:/usr/local/share/templates/navigation.tpl'}
But personally I would not recommend you to use this approach and stick to setTemplateDir and consistent place for templates in your app.
Little more information on that topic: https://www.smarty.net/docs/en/resources.tpl

Move 2sxc <script> to external file when it has razor content

I'm trying to make my CSP without unsafe inline.
Since I have to manually check every file from every app, I may as well move the scripts to external files instead of creating a million word CSP entry in the web.config by adding hashes or nounces.
This seems easy enough for client side content, but many templates have razor code in then such as:
<script>
alert(#myVar);
</script>
How can I move this to external?
So in general if you JS needs some input parameters you must of course put them somewhere, and only the razor will know what they are.
The simplest way is still to just have the initial call use the variables - like in your example above. If you have security concerns, doing type-checking in razor should eliminate that for you.
For example, if you do #((int)thing.property) than it simply cannot inject any unexpected payload.
If for some reason you really, really don't want this you can use a attribute-json convention, like
<div class="myGallery" init='{"files": 17}'> gallery contents </div>
and pick it up from the js you created. but this is quite a bit of work, so I would recommend the simpler way.

Making "personalized variables" in html

Okay, my english is not the greatest so I apologize in advance. Question is really stupid and I dont know how that is called but I will try to explain it here better. So I am making a template for one restourant and menus are changing every week. So is it possible to write paragraphs somewhere else ( in separated place (external or internal)) and then "call them" somewhere in .html.
Example. making methods in C# and then calling them anywhere when we want to
In my opinion the simplest method will be to use php.
Then in place with menu you can only use something like this:
<?php inlcude('menus/file.php');
And on server create a folder menus where you wil put php files with html.
All files can be simple html. There is no need to learn php just in place you want to call a file use code i placed earlier.
HTML doesn't have a good way to achieve this (although iframe exists).
This sort of thing is generally handled by software that generates the HTML, either when the page is requested (via something like the very basic SSI support in some webservers to full on server side programming (which you could use C# for)) or at publication time (via a build tool such as Gulp).
You could use jQuery to achieve it (if it is a simple website and simple menu), read more the related function on http://api.jquery.com/load/
You may also read a simple here: HTML File including another HTML file
I may also include a very basic example for you
main.html
<body>
<header>Some header</header>
<content>
<main class="the-menu"></main>
</content>
<script>
$(".the-menu").load("menu.html");
</script>
</body>

Is there such thing as a JSP minifier? (or Open Source HTML minifier)

This would be an HTML minifier that skips everything between <% and %>.
Actually, an Open Source HTML minifier would be a good starting place, especially if it already had code to preserve the contents certain blocks like <textarea. It's code might be able to be made to preserve <%%> blocks also.
I am aware that HTML minifiers are less common because that changes more often than JS/CSS and is often dynamically generated, but if the JSP compiler could be made to minify before making its compiled cache copy, it would result in minified HTML.
Also, an ASP minifier would probably be very close to the same thing. And I don't care about custom tags that have meaning to the server. The only stuff that matters to the server (for my company) is in the <%%> blocks.
This question is a bit outdated but an answer with a resource still hasn't made it's way to the posting.
HtmlCompressor makes this very thing possible and quite simply.
You can use it via Java API:
String html = getHtml(); //your external method to get html from memory, file, url etc.
HtmlCompressor compressor = new HtmlCompressor();
String compressedHtml = compressor.compress(html);
Or you can use it via Taglib:
Download .jar file of the current release and put it into your lib/ directory
Add the following taglib directive to your JSP pages:
<%# taglib uri="http://htmlcompressor.googlecode.com/taglib/compressor" prefix="compress" %>
Please note that JSP 2.0 or above is required.
In JSP:
<compress:html removeIntertagSpaces="true">
<!DOCTYPE html>
...
</html>
</compress:html>
Cheers
JSP is transformed to Java code and subsequntly compiled to bytecode. Minifying JSP has no purpose then.
You can process output generated by JSP page by writing custom filter. I have written filter to trim empty lines and unnecessary whitespace from JSP output, unfortunately it's not public. But if you google around, I'm sure you can find servlet filters to remove unneeded stuff from generated HTML.
Have a look at the Trim Filter (http://www.servletsuite.com/servlets/trimflt.htm), which you can simply map in your web.xml.
It will help you to remove whitespace, and can also strip off comments.
From my experience, whitespace occurs a lot in JSPs if you use tags that themselves don't have any output, such a the JSTL C control tags (c:if, c:choose, ...), and then this comes in very handy.
As you are already aware that HTML minification is less common and it also results in errors sometime than getting any benefit out of it. HTML is also dynamically generated content.
On the other hand, there are many better ways to speed up the application front end.
Minimizing HTTP requests
Minifying JS, CSS contents
gzip/deflate contents
Leveraging browser cache
Server Side caching, until resource changes
And many other - http://developer.yahoo.com/performance/rules.html
WebUtilities is a small java library to help speed up J2EE webapp front-end. Below is the link.
http://code.google.com/p/webutilities/
With new 0.0.4 version it does many optimization and results in significant performance boost. Please have a look in case you find it useful.

What are common file extensions for web programming languages?

What file extensions are used most commonly by different languages? Please don't put source file names (like .java) but rather extensions that would be present in a URL for rendered pages.
Here is my (alphabetized) list so far
ASP Classic
asp
ASP.NET
aspx
axd
asx
asmx
ashx
CSS
css
Coldfusion
cfm
Erlang
yaws
Flash
swf
HTML
html
htm
xhtml
jhtml
Java
jsp
jspx
wss
do
action
JavaScript
js
Perl
pl
PHP
php
php4
php3
phtml
Python
py
Ruby
rb
rhtml
SSI
shtml
TS
XML
xml
rss
svg
Other (C, perl etc.)
cgi
dll
Any more? I'll keep updating this based on comments. Largest correct additions (or deletions) is the accepted answer.
Aside: This is for comparing language use online: http://blog.paulisageek.com/2009/10/file-extensions-on-internet.html
Keep in mind that good URL design will completely hide any underlying file types.
I have created a Github gist that contains a list of programming languages and their extensions, here is a subset of the data included in the gist file:
{
"name":"CoffeeScript",
"type":"programming",
"extensions":[
".coffee",
"._coffee",
".cake",
".cjsx",
".cson",
".iced"
]
},{
"name":"ColdFusion",
"type":"programming",
"extensions":[
".cfm",
".cfml"
]}
I hope it is helpful.
languages.json.
.action — struts2
.do — struts1
.xml — XML
.rss — RSS feeds
.atom — Atom feeds(RSS)
(no extension) -- used now a days to increase readability of the URL, check stackoverflow URL
Ruby also tended to use .rhtml in the past.
Stellent uses the .hcsp extension for its page templates.
I believe Django uses .dtl.
.yaws (Erlang Yaws Web Server)
Here is an extension you forgot:
.adp — AOLServer using TCL
Ruby on Rails also uses the following internally for templates (files that are mostly HTML or JavaScript). So they're not really public facing, and are transparent to the end user/robot.
.html.erb
.erb
.rjs
Used to be that most CGI scripts were written in Perl.
IE specific strangeness:
.hta — html application
.htc — html components, allows you to alter IE behavior at runtime, from you website!
Also XML:
.svg — it's not just an image format!
.js, .html, .htm, .xhtml probably deserve a nod.
-SSI (Server Side Includes), use the extension .shtml
Add there:
ASP.NET
.axd
.asx
.asmx
.ashx
.aspx
.aspx
.asp
.css
REBOL tends to use .r
But .cgi is also used by some for REBOL CGI scripts.
ASP.NET needs a couple more, but I'm not sure this is exhaustive:
aspx
ascx
asmx (web services)
Here's a few of the commonly-used (but rarely enforced) extensions for some CSS dialects:
.hss for hss style sheets
.sass for sass style sheets
.less for less css style sheets
.ccss or .pcss for clever css style sheets
Going old school: .cgi
Typically written in C or Perl
.java .cs and .i_am_kidding_i_read_the_question.
On the serious side, swf (Flash) get hidden by the JS that loads them, generally, but they are extensions usually seen by the client. This is a limit case because it's not like JPEG (doesn't allow for web programming) nor like Javascript. But then, neither is PHP/ASP/JSP because from the client side it's just markup :)
.cs ----> C#
.kt ----> Kotlin
.json has become popular as a data xfer format
.png .jpg .gif are the most common graphics, but there are others.
Also video extensions