Equivalent of "Google Closure Compiler" for HTML? - html

Is there an equivalent of Google's Closure Compiler for HTML minimizing?

I presume you mean the Closure compiler, which effectively compresses javascript. If you search the goog for "HTML Compressor", you will find a lot of options catering to individual needs.

Consider HTML Tidy:
http://infohound.net/tidy/
It's a free tool that does a great job.

I think you can try google's mod_pagespeed, which will minify the response content.

I write a python script, replace all id and class name at pushlish. The script generate unique token for each class name and id, relpace the in both javascript,css and html template file. It workds greate for me

I am using Minify to trim and compress the html at runtime. The only requirements and setup are that you put Minify on your server and prepend the following code to the page.
<?php require $_SERVER['DOCUMENT_ROOT'] . '/min/pageBuffer.php'; ?>
<!-- html -->

Related

Using Dart functions inside HTML

Is it possible to use Dart functions inside <script> tags or other places in the HTML file, but the function body will be inside the Dart source file?
Sounds like you're looking for AngularDart. There may also be other frameworks but AngularDart is produced by Google to be used by Google.

Split html source into multiple files

Does HTML support splitting source over multiple files? I'm looking for some equivalent of C++'s #include; or maybe something like C#'s partial; an element that could take source path and inject the file contents at that place.
Apologies if this has been asked before. Google and SO searches didn't return much. I'm not a web guy, but the only solution I found was using an iframe, which many people do not like for various reasons.
It is just that my html source is becoming huge and I want to manage it by splitting into multiple files.
You can't, at least not in flat-HTML. What you can do is using Javascript to load and place the snippets. iframes are also non-ideal because contrary to what happens with directives like #include and partial, those snippets will never be compiled in one single page.
However, I think it's important here to understand how your pages will be served. Is this a static website? Because in this case I would write a simple script in your language of choice to compile the page. Let's say that you have a base like this:
<html>
<head>
<!-- ... -->
</head>
<body>
{{ parts/navigation.html }}
<!-- ... -->
</body>
</html>
You could write a script that runs through this file line by line and loads the content into a variable named, for example, compiled_html. When it finds {{ file }} it opens file, reads its content and append it to compiled_html. When it gets to the end, it writes the content of the variable into a HTML file. How you would implement it depends on the languages you know. I'm sure that it's pretty straightforward to do it in C#.
This way you'll be able to split the source of your HTML pages into multiple files (and reuse some parts if you need them), but you'll still end up with fully functional single files.
It is easily possible, if you are running PHP:
The PHP Language has the "include" command built in.
Therefore you can have your "index.php" (note you have to change the suffix, for the PHP parser to kick-in) and simply use following syntax.
<html>
<head>
[...] (header content you want to set or use)
</head>
<body>
<?php
include "relative/path/to/your/firstfile.html";
include "relative/path/to/your/secondfile.html";
include "relative/path/to/your/evenwithothersuffix/thirdfile.php";
include "relative/path/to/your/fourth/file/in/another/folder.html";
?>
[...] (other source code you whish to use in the HTML body part)
</body>
</html>
Basically making you main index.php file a container-file and the included html files the components, which you like to maintain seperately.
For further reading I recommend the PHP Manual and the W3Schools Include Page.
not possible with static html.
in general, this problem (lazy-fetching of content) is solved with a template processor.
two options:
template processor runs on the server side
any language
static website generators, server side rendering
template processor runs on the client side
javascript
web frameworks

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>

How can I modify a local HTML file in Perl?

Is there a CPAN module or code snippet that I can use to modify local HTML files without using a regExp?
What I want to do :
Change the start tag ( example : <div> to <div id="newtag"> )
Add a tag before another ( example : </head> to <script type="text/javascript"> ...</script></head>
Remove tags
Read the content of a given tag. (<- ok this can be done with an XML / HTML parser.
If you have HTML, and not XHTML, then you don't want to be using an XML parser.
HTML::Parser is the standard HTML parser for Perl. Pretty much everything else is built on top of it.
HTML::TokeParser is an alternative interface to HTML::Parser. It returns things on demand instead of passing everything to callbacks.
HTML::TreeBuilder builds a DOM-like tree from the HTML, which you can then modify.
HTML::TreeBuilder::XPath extends HTML::TreeBuilder with XPath support.
HTML::Query extends HTML::TreeBuilder with jQuery-like selectors.
pQuery is another module that brings more complete jQuery compatibility to HTML::TreeBuilder.
CPAN
XML::XPATH
XML::Xerces
A simple CPAN search returns
XML Search
XPATH
XPATH Tutorial
It sounds like you are not familiar with XPath. Here is a quick tutorial to get you familiar. Its not Perl but it will explain the concepts.

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