I am in the middle of a web app and we're just about to start with a cache-layer that features memcache and disk-based cache.
We just questioned ourself - what level/amount of formatting should we use on the stored cache data?
Let say that we have a database table called articles. Articles table have a number of columns including headline and content.
If we we're about to store this as an array, it would look like this:
array (
'headline' => 'Brilliant news - sunshine all week',
'content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis a
semper mi. Aenean rutrum ultrices mauris sed dictum. ');
Or, the pre-formatted HTML version:
<div class="article">
<h1>Brilliant news - sunshine all week</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis a
semper mi. Aenean rutrum ultrices mauris sed dictum. </p>
</div>
Pros and cons
Obviously, the pre-formatted html version increases the size of each cached datablock, since it includes a number of html tags. Also, there will be some headache included if the data were about to be formatted in different ways (I don't think that we will do this though). The option for that is of course to instead store multiple versions of each article in the cache.
So, what's common sense to do in our case? Let the HTML be rendered each time based upon the array that are retrieved from memcache, or just output the pre-formatted html?
I think it all depends on performance you need but I would use array version as it give possibility to play with content before rendering. Also building HTML having content is usually quite cheap when compared to getting content itself.
Related
I am using Angular6.
I have a pre tag with email text. Within this email text are tags like [cid:image001.jpg] which represent an image, using image001.jpg, I can retrieve that specific image from the back-end.
The problem is that I don't know how I can insert a new HTML element from the Typescript file into the pre tag, if this is even possible.
I have tried using a replace() method and replacing the '[cid:image001.jpg]' with '<img ...>' but it (understandably) gets interpreted as a string.
Help would be much appreciated.
Edit:
the positioning of the images is important, the <img> tag should appear where the [cid:image001.jpg] is, for example.
Example email:
Greetings,
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum
vehicula egestas elit viverra auctor. [cid:image001.jpg] Morbi at
nisi vel lorem porta pellentesque ut non urna.
Integer tempor tincidunt viverra. Vivamus ullamcorper et risus ac.
[cid:image002.jpg]
Best regards...
Can you try to pass the image in argument like this:
<img [cid]="pictureUrl">
I fixed this by doing the following, I changed:
<pre> {{emailText}} </pre>
To:
<pre innerHTML="safeHTML(emailText)"> </pre>
Where safeHTML() cleans the text so that scripting is not possible, this is important because it would be very unsafe otherwise.
Consider the example
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<p>In sed diam vitae justo laoreet ullamcorper.</p>
<p>Donec vehicula tellus vitae ligula finibus congue.</p>
<p>In ut sapien consectetur, efficitur ante et, interdum leo.</p>
It is rendered in a browser as expected with each paragraph on its own line:
Now when copying this text and pasting it into any plaintext context extra newlines appear:
Should you paste this into formatting-aware application (say LibreOffice Writer) no extra newlines this time:
And finally by copying this from LibreOffice Writer to the first mentioned plaintext editor we can get rid of these extra newlines:
Tried copying from Firefox and Chromium with the same results, so I assume it is universal among browsers.
Those screenshots were made on GNU/Linux with Geany and LibreOffice Writer. Absolutely the same behaviour is observed under MS Windows with Notepad++ and MS Office Word.
The questions are:
Why is it that newlines are added if pasting into plaintext application?
Is there any way to get rid of them if pasting into plaintext application?
I'm very new to coding, and am currently teaching myself html/css and i found that my paragraphs weren't centering in the middle of the page. I'd had my headline and sub headline labelled as h1 and h2, so i thought naturally the paragraphs would be the same (even though they had exactly the same declarations), yet when i changed both the elements to just p and brought them both under the same selector it worked. I was wondering if p1/p2 using would cause a lot of problems in the future? (this was before i was learning about ID's and classes, would that be the correct way to differentiate between paragraphs instead?)
please be kind, I've been learning less than a couple weeks:)
p1 and p2 are not valid HTML elements in themselves.
Granted, with HTML5, you can define your own elements where necessary, however this is usually reserved for instances where it makes your markup more semantic, and usually with a front-end framework or such.
With paragraphs, if you must differentiate between them, then I would suggest using classes.
<h1>Heading One</h1>
<h2>Heading Two</h2>
<p class="p1">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean volutpat efficitur magna eget tincidunt.</p>
<p class="p2">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean volutpat efficitur magna eget tincidunt.</p>
Paragraphs are always <p>. Only the header elements have this kind of numbering.
My personal reccomendation would be to use ID's rather than Classes. This is due to the nature of what seem to you want in your question.
ID's are unique - meaning that there can only be one of them per page.
Classes aren't unique - meaning that they can be assigned to multiple objects per page.
<p id="one">This is paragraph one.</p>
<p id="two">This is paragraph two.</p>
Before you slate me, yes I know that you shouldn't parse HTML with regex, you should use a dedicated parser. I don't have that option in the language I'm using (Xojo) and for various reasons, I need to use RegEx.
I'm trying to capture an entire block of HTML that may or may not contain nested HTML elements. Examples:
<blockquote> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
id sem consectetuer libero luctus adipiscing.</blockquote>
-----------------
<blockquote> This is the first level of quoting.
<blockquote> This is nested blockquote.</blockquote>
Back to the first level.</blockquote>
-----------------
<div>
Not nested
</div>
-----------------
<div>
Top level
<div>Nested</div>
</div>
I had come up with this pattern: <(\w*)>([\S\s]*?)<\/\1> but whilst it works for blocks of HTML it fails if the block contains a block of HTML with the same tags as the parent block. Online example here.
I'm using the PRCE variant of RegEx and coding in Xojo.
Does anyone have any useful advice on how to solve this problem? Thank you.
I am working on an HTML theme that contains several HTML templates with the same navigation panel, footer and assets. The problem is when I modify something in a footer, for example, I have to edit all other templates one by one to bring them into line. Is there any tools to automate this procees? Thanks in advance.
EDIT: I'm not aware if you can do this in normal HTML, but if you don't like my suggested method, you can check out .load() from Jquery: $(“#header”).load(“header.html”);
Sure. You can use something like Middleman or Jekyll for simple websites. It's very easy to learn and you can have a general layout, multiple layouts and even partials. Basically you're going to make a _footer.erb and render it in the layout.
If you have multiple pages like about, contact etc, and the structure of your website is not going to change (only content), I suggest you to use one layout and create some views that are yielded in there. It's a easy concept, you can learn it with middleman in few hours.
EDIT2:
How to use this
layout.haml:
%body
%header
%nav
= link_to 'index', '/index.html'
= link_to 'about', '/about.html'
= link_to 'contact', '/contact.html'
%section#wrapper
= yield
%footer
Something here
about.html.haml
%h2
About Us
%p
............
contact.html.haml
%h2
Contact
%p
Constact us at Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Donec sit amet placerat nisi.
Maecenas sollicitudin ut nisl a faucibus. Etiam et cursus eros.
Nulla ut tortor aliquam, rutrum diam vitae, posuere ante.
Basically you create a layout that goes for all pages and yield the content from other pages into it. Of course you can have multiple layouts and invoke different headers and footers from partial files but this is not the case you asked.
This is haml, middleman by default uses erb. You can convert this here if you need it.
I hope is clear enogh