In a Laravel setup using Laravel mix, the mix.js(['resources/js/app.js','resources/js/new-offer.js'], 'public/js') puts everything in one file, app.js.
What I am trying to achieve is to have multiple .js files each for one page. For example. I want to have index.js for my index.blade.php and new-offer.js for my new-offer.blade.php etc ...
The idea is that each page is server side rendered and each page represents a static page comming fromm the server and each one should has it's own set of js files that works in. How this should be done, is it recommended, what are other arhcitectures ?
You can use multiple concatenated .js(...) statements. In your case:
mix.js('resources/js/app.js','public/js').js('resources/js/new-offer.js' ,'public/js')
This will createapp.js and new-offer.js files in your public js folder
Related
I've got the following structure:
pages/blog/[...slug].jsx
pages/blog/Create.jsx
The main problem is, I've got no idea how to make the "create" file unavailable for a browser navigation.
I need to open this "Create" page (Component) in my slug file. I know, I can create another directory and add files like that over there, but I don't find a such type of approach convenient.
Can I do something like this in the nextjs context?
Make a seperate folder other than pages ,like example components folder
-pages
->blog
->[slug].jsx
-components
->Create.jsx
Now u can import Create.jsx in your [slug].jsx file.
How can I load all html files in a folder into a content? I have about 125 html files in a folder src and need to load them in a content called .content.
$(".content").load("src/1.html");
is this doable on client side using JavaScript?
I belive you need to use PHP to get the numbers of files on a specific folder on your root directory.
http://php.net/manual/en/function.scandir.php
If you read this, you will be able to get the folder array by using PHP and they you can use JS or JQuery to do rest.
I am making a webapp:frontend in Angular and backend in Rails.
I have decoupled frontend and backend.
Qestion 1: All my html and javascript files are in public folder right now. Here are paths.
html path: root/public/html/..
javascript path: root/public/javascript/..
The problem I'm facing right now is that I make all my http requests in javascript files and anyone can see it since it is in public folder. I'm wondering what is the best practice to hide my javascript files. Is it just easy as taking out from the public folder and putting it outside of public folder scope?
Question2:
I'm using font-awesome. I was using CDN previously but I decided to download the css and use it locally. I have put into my project in following path: root/vendor/font-awesome/css/font-awesome.css
However, It was not displaying icons successfully. So I did a test. I put the css file in root/public/css/font-awesome.css and it starts displaying the icons. Do you know why the css file is not being read?
Thanks.
I have a lot of .asciidoc files (~50). Basically, I want to create a website that can show the content of all these files on the webpage.
Till now, everything that I found basically converts the .asciidoc file into an individual .html file. This means I'll have ~50 .html files which I don't really want to do.
Is there anyway so that I can have a single webpage and somehow insert the contents of the .asciidoc file in the backend? Like PHP?
Sure, this can be done, but not by asciidoctor itself. Take a look at the OpenDevise landing page. You can see they're loading the files through the Asciidoctor API. You could do the same thing with shelling out or using the JavaScript port (asciidoctorjs). The main idea is to have something else generating a scaffold or template and then calling out to asciidoctor somehow to get the content.
It all works in my local server, but when others try to deploy what I have done to the server, it fails.
the file system is the server something like:
SERVER_FOLDER
--homepage
----static
----templates
------404.html
----app.py
----config.py
for example: The server is: MY_SERVER
and then in my app.py, I use
#app.route('/homepage/')
#app.route('/homepage/index')
def index():
# TODO
to define the homepage, and #app.errorhandler(404) to redirect all the not found page to 404.html
So I can get access to my homepage with http://MY_SERVER/homepage/, a little different than my local server. That's one thing that I am confused.
What I think is that the app.py runs under the MY_SERVER rather than MY_SERVER/homepage right?
But, in this way, when I run a template in my template file, and the html template file will use the js file under the static folder. the response always shows the js file is not found.
when I use <script src="{{ url_for('static', filename='file.js') }}"></script>, it shows not found in MY_SERVER/static and return to 404
when I try <script src="../homepage/static/file.js"></script>, same result.
How to handle this?
Build toward your solution:
Get flask serving image files from static
Put an image in the static directory and call it from your browser: http://yoursite/static/some_image_there.jpg
Plug away until that works.
Get flask serving the js file directly to your browser
Now put your js file into static and do as you did for the image.
Plug away until you can call it from the browser:
http://yoursite/static/yourfile.js
get your html to call the js file from static
Now you know that there is no problem actually serving the file, and you know the exact url to it. So it's not a big step to getting the HTML to reference it and your browser to load it.